-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Add 'T | PromiseLike<T>' inference from awaited types #37615
Conversation
@typescript-bot perf test |
Heya @rbuckton, I've started to run the perf test suite on this PR at 39eb820. You can monitor the build here. Update: The results are in! |
The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master. |
@rbuckton Here they are:Comparison Report - master..37615
System
Hosts
Scenarios
|
39eb820
to
17517d5
Compare
then<ARD = never, AJD = never, ...>(
doneFilter: (t: TR, u: UR, v: VR, ...s: SR[]) => PromiseBase<ARD, AJD, ...> | Thenable<ARD> | ARD,
failFilter: (t: TJ, u: UJ, v: VJ, ...s: SJ[]) => PromiseBase<ARF, ...> | Thenable<ARF> | ARF,
progressFilter: (t: TN, u: UN, v: VN, ...s: SN[]) => PromiseBase<ARP, ...> | Thenable<ANP> | ANP
): PromiseBase<ARD | ARF | ARP, AJD | AJF | AJP, ...>;
Upon further review this is not an issue with subtype reduction, but rather with this algorithm as it does not handle inference for the other type arguments to |
@typescript-bot perf test |
Heya @rbuckton, I've started to run the perf test suite on this PR at 3d2ac60. You can monitor the build here. Update: The results are in! |
@rbuckton Here they are:Comparison Report - master..37615
System
Hosts
Scenarios
|
3d2ac60
to
24b6d64
Compare
@typescript-bot run dt |
@typescript-bot user test this |
@ahejlsberg, @weswigham I'd appreciate if you could take a look. |
@rbuckton is this for 3.9 or 4.0? |
I was hoping for 3.9, as this was initially part of |
I think we should take this as an item in the design meeting to understand whether it goes in regardless of awaited. It's way too late in the game to add it to 3.9 IMO. |
Unfortunately, we never finished reviewing this PR. It is pretty old now, so I'm going to close it to reduce the number of open PRs. |
This re-introduces the
T | PromiseLike<T>
inference heuristic previously added in theawaited
type PR. This heuristic improves type inference for cases where we are inferring to a union consisting of a single type variableT
and one or morePromise
-like types whose "promised type" (i.e., the type of thevalue
parameter to theonfulfilled
callback) is preciselyT
. This primarily impacts inference for cases likePromise.resolve
andPromise#then
:One minor change vs. the implementation in the
awaited
types implementation is that this version detects unions with more than two constituents (i.e.,T | PromiseLike<T> | Promise<T>
) as long as all of the constituents are essentially promises forT
.