-
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
Improve type inference for types like 'T | Promise<T>' #32460
Conversation
@typescript-bot run dt |
Heya @ahejlsberg, I've started to run the extended test suite on this PR at c6b77fa. You can monitor the build here. It should now contribute to this PR's status checks. |
Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at c6b77fa. You can monitor the build here. It should now contribute to this PR's status checks. |
Latest commit fixes an issue where strangely we infer nothing for declare function flatten<T>(array: ReadonlyArray<ReadonlyArray<T>>): T[];
declare let naa: number[][];
let na = flatten(naa); Before the commit, |
@typescript-bot run dt |
Heya @ahejlsberg, I've started to run the extended test suite on this PR at 8f02055. You can monitor the build here. It should now contribute to this PR's status checks. |
Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at 8f02055. You can monitor the build here. It should now contribute to this PR's status checks. |
@ahejlsberg you're probably very busy, but in case you find the time, it would be great if you could have a look at #32100 🙏 |
@typescript-bot run dt |
Heya @ahejlsberg, I've started to run the extended test suite on this PR at 623a172. You can monitor the build here. It should now contribute to this PR's status checks. |
Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at 623a172. You can monitor the build here. It should now contribute to this PR's status checks. |
RWC tests look good. Only one change in |
@typescript-bot run dt |
Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at 2541a5d. You can monitor the build here. It should now contribute to this PR's status checks. |
@typescript-bot run dt |
Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at 9b2d9cd. You can monitor the build here. It should now contribute to this PR's status checks. |
@typescript-bot user test this |
Heya @ahejlsberg, I've started to run the parallelized community code test suite on this PR at 203fd9f. You can monitor the build here. It should now contribute to this PR's status checks. |
The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master. |
Verified that user test suite differences are all preexisting conditions. |
@typescript-bot run dt |
Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at 5646856. You can monitor the build here. It should now contribute to this PR's status checks. |
Two minor issues in DT tests are covered by DefinitelyTyped/DefinitelyTyped/pull/37057. |
Merging this now. There are a few breaks in the RWC suites that I have reviewed with @RyanCavanaugh. |
I think this is significantly affecting |
Scratch that, it might be the node version bump itself that's breaking so much; or at least a fair part of it. |
This PR improves type inference to union types that contain combinations of nested and naked type variables. Previously, we'd always give lower priority to inferences made to naked type variables in union types, but this produced sub-optimal results in some fairly basic scenarios (see #32434).
The improved algorithm for inferring from a single source type or a union of source types to a target union type is:
Some examples:
Previously both of the examples above caused errors.
This PR also fixes an inconsistency we've long had.
We now infer
unknown
forT
in both cases above (because there is nothing left to infer from when the matching types are eliminated, andT
has no constraint or default).Fixes #32434.