-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Awaitable type is not additive #51111
Comments
I, too, observe this issue. Interestingly enough, this even fails for intersecting a normal value with an awaitable one: type A = {a: string}
type B = {b: string}
type Awaitable<T> = T | PromiseLike<T>
type C = A & Awaitable<B> // just this breaks it
async function f(c: C) {
(await c).a
} This means that in this code snippet: type Q0 = C extends A ? true : false
type Q1 = Awaited<C> extends A ? true : false we can see |
What runtime value |
I wonder if this is ultimately due to something like #14107. For any promise-ish thing ((f: (v: A) => R) => R) & ((f: (v: A) => R) => R)
⇓ ⇓ ⇓ 👎 #14107
(f: ((v: A) => R) | ((v: B) => R)) => R
⇓ ⇓ ⇓ 👍 #29011
(f: (v: A & B) => R) => R Without a fix for #14107 I'm not sure how we could fix this (well, I suppose it could be special-cased, like anything) |
The core thing here is that Promises are understood primarily in terms of their let myC: C = {
then: (cb: ((a: A) => PromiseLike<any>) & ((b: B) => PromiseLike<any>)) => {
return cb({ b: "" });
}
} |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
🔎 Search Terms
Awaitable, MaybePromise
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
The types are not additive (
Awaited<Awaitable<A> & Awaitable<B>>
!=A & B
)🙂 Expected behavior
The types should be additive (
Awaited<Awaitable<A> & Awaitable<B>>
=A & B
)Related: #31394
The text was updated successfully, but these errors were encountered: