-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Description
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.5and4.7.0-dev.20220503.4.4.4and lower are unaffected by this bug.
⏯ Playground Link
Playground link with relevant code
💻 Code
type A = Promise<number> & number;
const a = {} as A;
const b = await a;
type B = typeof b; // B should be "number", but it is "Promise<number> & number"!
a.then((c) => {
type C = typeof c; // C is "number" (which is corrent)
});
type D = 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 B has to be equal to C and D.