Closed
Description
openedon May 6, 2022
Bug Report
π Search Terms
narrowing generic parameter
π Version & Regression Information
- This changed between versions 4.4.3 and 4.6.4
β― Playground Link
Playground link with relevant code
Changing the version to 4.4.4 works
π» Code
Reduced example, the code on the playground is an actual function from our codebase that used to work fine.
type TimestampColumns<T> = {
[K in keyof T]: T[K] extends Date ? K : never
}[keyof T];
function getTimestamp<Row extends Record<string, unknown>, K extends TimestampColumns<Row>>(
row: Row,
timestampColumn: K,
): number {
const date: Date = row[timestampColumn]; // This used to work;
return date.valueOf();
}
π Actual behavior
The code should compile with no warnings or errors.
π Expected behavior
Fails with error Type 'Row[K]' is not assignable to type 'Date'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment