Repository navigation
Check for keyof constraint type instead of syntactic check - #24098
Merged
Wesley Wigham (weswigham) merged 5 commits intoMay 22, 2018
Merged
Wesley Wigham (weswigham) merged 5 commits into
Wesley Wigham (weswigham) merged 5 commits into
Conversation
Wesley Wigham (weswigham)
requested review from
Anders Hejlsberg (ahejlsberg) and
Mohamed Hegazy (mhegazy)
May 14, 2018 17:10
Member
|
I'm not sure I like this. It's really odd that |
Wesley Wigham (weswigham)
force-pushed
the
keyof-contextual-type-fix
branch
from
May 17, 2018 22:43
7332390 to
23510e8
Compare
Member
Author
|
Anders Hejlsberg (@ahejlsberg) So I've generalized it to just being a type variable constrained to any of string or number or symbol (rather than exactly one of them)... and there's no diff to any tests, |
Anders Hejlsberg (ahejlsberg)
approved these changes
May 20, 2018
Anders Hejlsberg (ahejlsberg)
left a comment
Member
There was a problem hiding this comment.
Approved with the noted change.
| return isTypeParameterWithKeyofConstraint(contextualType) && maybeTypeOfKind(candidateType, TypeFlags.StringLiteral | TypeFlags.NumberLiteral | TypeFlags.UniqueESSymbol) || | ||
| constraint.flags & TypeFlags.String && maybeTypeOfKind(candidateType, TypeFlags.StringLiteral) || | ||
| constraint.flags & TypeFlags.Number && maybeTypeOfKind(candidateType, TypeFlags.NumberLiteral) || | ||
| constraint.flags & TypeFlags.Boolean && maybeTypeOfKind(candidateType, TypeFlags.BooleanLiteral) || |
There was a problem hiding this comment.
The line that checks for TypeFlags.Boolean isn't necessary. The logic already covers unions of literal types, and TypeFlags.Boolean is just a convenience flag we set on the built-in true | false union.
Wesley Wigham (weswigham)
added a commit
to weswigham/TypeScript
that referenced
this pull request
May 23, 2018
…#24098) * Check for keyof constraint type instead of syntactic check * Readopt older candidateType check, even though it shouldnt really matter * OK. Just use maybetypeOfKind * Remove redundant boolean check
Mohamed Hegazy (mhegazy)
added a commit
that referenced
this pull request
May 23, 2018
Check for keyof constraint type instead of syntactic check (#24098)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #24080
Downside:
T extends string | symbol | numberwill now produce literals. (technically a break)Upside:
T extends string | symbol | numberwill now produce literals. (probably desirably, given any one of those on their own would produce literals)