Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'keyof' for constrained type parameters #12026

Merged
merged 5 commits into from
Nov 3, 2016
Merged

Conversation

ahejlsberg
Copy link
Member

This PR introduces two assignability rules to properly support constrained type parameters in conjunction with the keyof type operator:

  • Given a type parameter K with a constraint keyof T, a type S is assignable to K if S is assignable to keyof T.
  • Given a type parameter T with a constraint C, a type S is assignable to keyof T if S is assignable to keyof C.

Fixes #12011.

@DanielRosenwasser
Copy link
Member

Linting errors!

10:14:39 src/compiler/checker.ts[6831, 25]: Identifier 'constraint' never appears on the LHS of an assignment - use const instead of let for its declaration.
10:14:39 src/compiler/checker.ts[6841, 25]: Identifier 'constraint' never appears on the LHS of an assignment - use const instead of let for its declaration.
10:14:46 scripts/tslint/preferConstRule.ts[5, 186]: Unnecessary semicolon
10:14:49 scripts/tslint/booleanTriviaRule.ts[5, 143]: Unnecessary semicolon

@DanielRosenwasser
Copy link
Member

Otherwise looks good to me. 👍

@ahejlsberg ahejlsberg merged commit 702efd5 into master Nov 3, 2016
@mhegazy mhegazy deleted the keyofAndConstraints branch November 3, 2016 21:43
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants