You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code compiles without an error or warning. Because JavaScript promises get automatically unwrapped, f1, f2, f3 and f4 have essentially the same behavior to the caller, they all return a promise that resolves to a number, which is inconsistent with the return type of f4, Promise<Promise<number>>.
π Expected behavior
There should be an error or a warning for f4, suggesting the type should be Promise<number>. FWIW, it is impossible to have a promise that resolves to another promise in JavaScript, so nested Promise<Promise<number>> doesn't make sense and can be misleading.
For example, a person coming from C# (where nested tasks like Task<Task<int>> is a legit concept), might be tempted to do this in TypeScript:
Bug Report
π Search Terms
Nested promises, promise of promise
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
This code compiles without an error or warning. Because JavaScript promises get automatically unwrapped,
f1
,f2
,f3
andf4
have essentially the same behavior to the caller, they all return a promise that resolves to a number, which is inconsistent with the return type off4
,Promise<Promise<number>>
.π Expected behavior
There should be an error or a warning for
f4
, suggesting the type should bePromise<number>
. FWIW, it is impossible to have a promise that resolves to another promise in JavaScript, so nestedPromise<Promise<number>>
doesn't make sense and can be misleading.For example, a person coming from C# (where nested tasks like
Task<Task<int>>
is a legit concept), might be tempted to do this in TypeScript:This code compiles, but doesn't behave as one may expect. The inferred type for
innerPromise
is actuallynumber
, notPromise<number>
.The text was updated successfully, but these errors were encountered: