Open bsimonjc opened 1 year ago
This definitely seems wrong. Is there any work planned to fix this? The following behaviors that appear to be bugs are as follows.
// it's correct
const resolve: Promise<number> = Promise.resolve(Promise.resolve(Promise.resolve(0)))
async function pr<T>(v: T) {
return v
}
// it's should be Promise<number>
const promise: Promise<Promise<Promise<number>>> = pr(pr(pr(0)))
const a: any = 0
;(a as Promise<Promise<Promise<number>>>).then(
// value is should be number
(value: Promise<Promise<number>>) => {}
)
Bug Report
π Search Terms
promise constructor
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
Return type of the promise constructor doesn't unwrap nested promises
π Expected behavior
The return type of the promise constructor should match the runtime behavior
The current constructor type is
{ new <T>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>; }
Shouldn't the return type actually be
Promise<Awaited<T>>
like it is forPromise.resolve()
? Is there something I'm missing here?