Skip to content

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

Closed
Mateusz Burzyński (Andarist) wants to merge 3 commits into
microsoft:mainfrom
Andarist:andarist/filter-instantiation-expressions-by-matching-constraints
Closed

Mateusz Burzyński (Andarist) wants to merge 3 commits into
microsoft:mainfrom
Andarist:andarist/filter-instantiation-expressions-by-matching-constraints

Conversation

@Andarist

@Andarist Mateusz Burzyński (Andarist) commented Nov 30, 2022 •

Copy link
Copy Markdown
Contributor

fixes #51694
fixes #63126

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 (typescript-bot) added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Nov 30, 2022
Comment thread src/compiler/checker.ts
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
Copy Markdown
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.

Comment thread src/compiler/checker.ts
if (applicableSignatures.length) {
return applicableSignatures;
}
return sameMap(sameTypeAritySignatures, sig => {

Copy link
Copy Markdown
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.

@typescript-bot

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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
Mateusz Burzyński (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
@typescript-bot

Copy link
Copy Markdown
Contributor

With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies).

Next steps for PRs:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

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: Done

5 participants