... but with that being said, 3.7 seems to have broken many aspects of the `Promise.all` interface. Right now the largest issue seems to be that if any `Promise` result in `Promise.all` is nullable, all of the results are nullable.
... but with that being said, 3.7 seems to have broken many aspects of the `Promise.all` interface. Right now the largest issue seems to be that if any `Promise` result in `Promise.all` is nullable, all of the results are nullable.
The result should instead be a tuple, but IDK how well tuple size inference would work in a case like that.
type Tuple<T, K> = [T, K | null];
Which is my first thought, but I can’t test it against the compiler at the moment and I’m not sure if I’m missing something....JavaScript would allow you to extend that list during runtime (unless you freeze it)
type Tuple<T, K> = [T, K]
const Tuple<T, K> = (x: T, y: K): Tuple<T, K> => {
const tup = [x, y];
Object.freeze(tup);
return tup;
};It is a well hidden secret, and one that I'm not going to try to lookup the docs for on mobile, but the idea is that the operator strips null/undefined from the type of whatever is before it.
So you can do something like this:
const [ a, b ] = await Promise.all([
async () => ({ foo: 'bar' }),
() => null
])
console.log(a!.foo) // `a!` strips the nullable off `a`I thought you had to actually provide a Promise to `Promise.all`, not functions that return promises (you have to invoke the functions):
const [ a, b ] = await Promise.all([
(async () => ({ foo: 'bar' }))(),
(() => null)(),
])
When I do this, `a` and `b` have their proper types.