-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Feed the 'this' type as a type argument to constraints during relation checking #7290
Conversation
if (!constraint || constraint.flags & TypeFlags.Any) { | ||
constraint = emptyObjectType; | ||
} | ||
|
||
// The constraint may need to be further instantiated with its 'this' type. | ||
constraint = getTypeWithThisArgument(constraint); |
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.
Let me check my understanding: an unconstrained type parameter gets 'any' or '{}' as its constraint, which shouldn't have a this-type, so this is a no-op there. Am I right?
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.
Yup. I could have introduced an else
branch, but I figured that this would be a little simpler to read. I'm open to changing it.
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.
No, I think it's fine. Just checking.
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.
You want to instantiate the constraint with source
as the this-type parameter, so this line should be:
constraint = getTypeWithThisArgument(constraint, source);
As you have it now you're instantiating the constraint with its own this-type as the this-type parameter. I think the reason it works with the example in the bug is because the this-type of Something
is assignable to the this-type of Bar
, but it's not the right solution.
👍 |
@DanielRosenwasser can you update the PR and respond to the remaining comments. |
Fixes #7276.
@ahejlsberg @sandersn @RyanCavanaugh can you take a look?
Right now, the types are being instantiated with their
target
. Is this sufficient?