-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Just map type variables to constraints at certain positions for narrowing so that we do not map primitives #21384
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
Just map type variables to constraints at certain positions for narrowing so that we do not map primitives #21384
Conversation
sandersn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix looks good, but I’d like more work put in on clarifying the constraint concept to prevent future bugs.
src/compiler/checker.ts
Outdated
| return !!(typeParameter.symbol && forEach(typeParameter.symbol.declarations, decl => isTypeParameterDeclaration(decl) && decl.default)); | ||
| } | ||
|
|
||
| function getConstraintType(type: Type): Type { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a thicket of related concepts here now that need better names: base constraint, syntactic constraint and this concept — constraint? — that I think is the correct one to use most of the time. But it doesn’t support index access types, for example.
Let’s talk in person and look over the current set of constraint-related functions. I don’t think we should be using the syntactic constraint much anymore, but I’m not sure of the best way to make that happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeFlags.TypeVariable includes indexed accesses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After talking in person, I've since swapped just reusing mostof getBaseConstraintOfType, since that handles most of the behaviors we wanted anyway (including handling intersections correctly).
src/compiler/checker.ts
Outdated
| return type; | ||
| } | ||
|
|
||
| function getBaseConstraintOrType(type: Type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would inline this to avoid introducing a new name that differs by one (1) character from getBaseConstraintOfType.
Or put both of those functions right next to each other.
a0cb0a3 to
e3a3b9a
Compare
e3a3b9a to
68e594a
Compare
Fixes #21360
I've also renamed the associated functions as appropriate, since they no longer deal with apparent types.