Skip to content

Narrowing of generic type parameter indexΒ #48996

Closed

Description

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

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions