-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Filter signatures by matching constraints when instantiating them for instantiation signatures #51695
base: main
Are you sure you want to change the base?
Conversation
… instantiation signatures
src/compiler/checker.ts
Outdated
const applicableSignatures = mapDefined(sameTypeAritySignatures, sig => { | ||
const typeArgumentTypes = checkTypeArguments(sig, typeArguments!, /*reportErrors*/ false); | ||
return typeArgumentTypes && getSignatureInstantiation(sig, typeArgumentTypes, isInJSFile(sig.declaration)); | ||
}); |
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.
Note that this still doesn't exactly work like regular overload selection done by chooseOverload
. I simply reject signatures that have non-matching constraints on their type params. When overloads are chosen for call expressions etc the first matching overload "wins".
I think that this is actually desirable - since here we still output an intersection of signatures (overloads) and we leave the final overload selection for the time the output type is being used as a call expression.
src/compiler/checker.ts
Outdated
if (applicableSignatures.length) { | ||
return applicableSignatures; | ||
} | ||
return sameMap(sameTypeAritySignatures, sig => { |
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've preserved the old behavior here~. If there are some signatures for the given type argument arity but when none of them match... I still gonna report the same error. Perpahs this can be improved further.
The TypeScript team hasn't accepted the linked issue #51694. If you can get it accepted, this PR will have a better chance of being reviewed. |
2 similar comments
The TypeScript team hasn't accepted the linked issue #51694. If you can get it accepted, this PR will have a better chance of being reviewed. |
The TypeScript team hasn't accepted the linked issue #51694. If you can get it accepted, this PR will have a better chance of being reviewed. |
…ntiation-expressions-by-matching-constraints
ff7f0c6
to
ba3e829
Compare
…ntiation-expressions-by-matching-constraints
fixes #51694
There are some open questions related to the design of instantiations expressions and how they relate to overloads etc. But since I was looking into the implementation to see why the reported issue doesn't type-check OK, I've figured out I can create a draft that would address that as the change was fairly easy to introduce.