-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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 return type inferences by constraint applicability #58910
base: main
Are you sure you want to change the base?
Filter return type inferences by constraint applicability #58910
Conversation
34d5fbe
to
b9936e3
Compare
…-type-inference-by-constraint-applicability
src/compiler/checker.ts
Outdated
} | ||
else { | ||
if (inference.priority! & InferencePriority.ReturnType) { | ||
inference.inferredType = filterContextualInferredType(inferredType, instantiatedConstraint) ?? (fallbackType && filterContextualInferredType(fallbackType, instantiatedConstraint)) ?? instantiatedConstraint; |
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.
We only need to bother with this filtering if the constraint check for the whole union fails, right? (Since if it passes, no filtering will occur, as every union member must also pass.) This can probably be inside the comparison branch below?
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.
That’s right but it felt cleaner to have this in a separate branch. Shouldnt filterType already optimize for array/type allocations?
@typescript-bot test it |
Hey @jakebailey, the results of running the DT tests are ready. There were interesting changes: Branch only errors:Package: jest
|
@jakebailey Here are the results of running the user tests with tsc comparing Something interesting changed - please have a look. Details
|
@jakebailey Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
@jakebailey Here are some more interesting changes from running the top 400 repos suite Details
|
This had a ton of breaks on the extended tests, so seems like not a good idea? |
yep, might not be a good idea after all - I didn't yet look at those breaks though, at the very least I'd like to get some new test cases based on them so we could add them to |
…-type-inference-by-constraint-applicability
Slimmed down repro based on type Query = (
container: HTMLElement,
...args: any[]
) =>
| Error
| HTMLElement
| HTMLElement[]
| Promise<HTMLElement[]>
| Promise<HTMLElement>
| null;
interface Queries {
[T: string]: Query;
}
type FindByText<T extends HTMLElement = HTMLElement> = (
container: HTMLElement,
text: string,
) => Promise<T>;
declare function findByLabelText<T extends HTMLElement = HTMLElement>(
...args: Parameters<FindByText<T>>
): ReturnType<FindByText<T>>;
const queries = {
findByLabelText,
};
type MapQueries<Q extends Queries = typeof queries> = {
[P in keyof Q]: Q[P];
}; I didn't quite expect a change in any code like this... I'll continue investigating this. |
@typescript-bot test it |
@typescript-bot test it |
Hey @jakebailey, the results of running the DT tests are ready. Everything looks the same! |
@jakebailey Here are the results of running the user tests with tsc comparing Something interesting changed - please have a look. Details
|
@jakebailey Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
@jakebailey Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
@gabritto I made a very silly mistake initially. It was somewhat a coincidence that the tests I had passed 😅 This was fixed now and I added extra test cases. The PR is now in a good state and can be reviewed :) Above we can see some missing implicit anys in webpack. I added a test case based on that, this is a clear improvement. |
Aside from the new return type branch, it seems like this also changes the |
No, that wasn't intentional. Thanks for pointing that out - I corrected the PR but I doubt it will make a difference for any of the extended tests. |
fixes #50719
fixes #41461