Improve Promise constructor return type #32254
I tried looking for this, but didn't find anything related to it.
new promise constructor return type generic inferred
const promised4 = new Promise(resolve => resolve(4)); // typeof promised4 === 'Promise<unknown>' // it should be `Promise<4>'
You can already use the generic for this, but this can be automated.
const promised4 = new Promise<4>(resolve => resolve(4)); // typeof promised4 === 'Promise<4>'
My suggestion meets these guidelines:
Note: it would be a good break because Promises become typed.
It looks like the type should to that already, but I'm testing on 3.6.0-dev.20190704 and
You can also replicate the issue on the repl: https://www.typescriptlang.org/play/#code/MYewdgzgLgBAtgUwhAhgcwTAvDMCDuMACgE4hwCWECAFCUiADYBumWAfDPRE6zQCwBKQUA
But strangely the definition is different
This is a known limitation of the type inference machinery - it can't infer the promise's
That's weird, I'm almost pretty sure I did that once: https://github.com/bfred-it/webext-options-sync/blob/cbf837e6b2bd93e0e39fe0d43a8b47cdde9e53fd/source/index.ts#L66-L68
(The types for that function ultimately failed because I couldn't type