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

Filter signatures by matching constraints when instantiating them for instantiation signatures #51695

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

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.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Nov 30, 2022
Comment on lines 33701 to 33704
const applicableSignatures = mapDefined(sameTypeAritySignatures, sig => {
const typeArgumentTypes = checkTypeArguments(sig, typeArguments!, /*reportErrors*/ false);
return typeArgumentTypes && getSignatureInstantiation(sig, typeArgumentTypes, isInJSFile(sig.declaration));
});
Copy link
Contributor Author

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.

if (applicableSignatures.length) {
return applicableSignatures;
}
return sameMap(sameTypeAritySignatures, sig => {
Copy link
Contributor Author

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.

@Andarist Andarist marked this pull request as ready for review November 30, 2022 10:31
@typescript-bot typescript-bot removed the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Dec 20, 2022
@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Dec 20, 2022
@typescript-bot
Copy link
Collaborator

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
@typescript-bot
Copy link
Collaborator

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.

@typescript-bot
Copy link
Collaborator

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
@Andarist Andarist force-pushed the andarist/filter-instantiation-expressions-by-matching-constraints branch from ff7f0c6 to ba3e829 Compare June 13, 2023 11:42
…ntiation-expressions-by-matching-constraints
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Status: Waiting on reviewers
Development

Successfully merging this pull request may close these issues.

Instantiation expressions don't filter signatures with non-matching constraints
3 participants