I have a LazyPromise
object with all
method. It works like Promise.all
but the promises start the call not on initialization, eg.:
// It started executing as soon as it was declared
const p1 = Promise.all([Promise.resolve(1), Promise.resolve('foo')])
// It started executing only when `p2.then()` is called
const p2 = LazyPromise.all([() => Promise.resolve(1), () => Promise.resolve('foo')])
this is the implementation
class LazyPromise {
static all(lazies: Array<() => Promise<any>>){
return Promise.all(lazies.map(lazy => lazy()));
}
}
usage
const result = LazyPromise.all([() => Promise.resolve(1), () => Promise.resolve('foo')]).then(result => console.log(result))
I want make the result with correct types.
Now result is a any[]
I want: [number, string]
How infer the correct result types?