Bug Report
When we make an intersection of a promise with a primitive type like Promise<T> & T (where T is primitive (non-object)), the resulting type from await (Promise<T> & T) is wrong (still contains a promise). This is clearly a bug since Awaited<Promise<T> & T> and (Promise<T> & T).then(x => {}) behave correctly (the result is only T). The issue is only observed when using the await keyword.
The types arrangement might seem arbitrary, but it has a valid use case which is provided in the playground link below.
🔎 Search Terms
PROMISE & PRIMITIVE, PROMISE INTERSECTION, AWAITED TYPE, INCONSITENT THEN AND AWAIT
🕗 Version & Regression Information
Tested only versions available on playground!
- This changed between versions
4.5.5 and 4.7.0-dev.20220503. 4.4.4 and lower are unaffected by this bug.
⏯ Playground Link
Playground link with relevant code
💻 Code
typeA=Promise<number>&number;consta={}asA;constb=awaita;typeB=typeofb;// B should be "number", but it is "Promise<number> & number"!a.then((c)=>{typeC=typeofc;// C is "number" (which is corrent)});typeD=Awaited<A>// D is "number" (which is corrent)🙁 Actual behavior
Type B still contains Promise<number> despite of the value being awaited.
🙂 Expected behavior
In the example above Bhas to be equal to C and D.
Bug Report
When we make an intersection of a promise with a primitive type like
Promise<T> & T(where T is primitive (non-object)), the resulting type fromawait (Promise<T> & T)is wrong (still contains a promise). This is clearly a bug sinceAwaited<Promise<T> & T>and(Promise<T> & T).then(x => {})behave correctly (the result is onlyT). The issue is only observed when using theawaitkeyword.The types arrangement might seem arbitrary, but it has a valid use case which is provided in the playground link below.
🔎 Search Terms
PROMISE & PRIMITIVE,PROMISE INTERSECTION,AWAITED TYPE,INCONSITENT THEN AND AWAIT🕗 Version & Regression Information
4.5.5and4.7.0-dev.20220503.4.4.4and lower are unaffected by this bug.⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Type
Bstill containsPromise<number>despite of the value being awaited.🙂 Expected behavior
In the example above
Bhas to be equal toCandD.