TypeScript Version: 3.1
Search Terms: type inferrence
Code
functionreduceToPromise<Textendsstring>(promise: Promise<T>,items: string[]){returnpromise}constinitialPromise: Promise<string>={}asany;constitems: string[][]=[];constreducedOne=items.reduce(reduceToPromise,initialPromise);constreducedTwo=items.reduce((promise,items)=>reduceToPromise(promise,items),initialPromise);Playground
Expected behavior:
Both reducedOne and reducedTwo should be typed as Promise<string>
Actual behavior:
reducedOne is typed as {}
This issue only occurs when the function has a generic type. This works fine:
functionreduceToPromise(promise: Promise<string>,items: string[]){returnpromise}constinitialPromise: Promise<string>={}asany;constitems: string[][]=[];constreduced=items.reduce(reduceToPromise,initialPromise);Playground
TypeScript Version: 3.1
Search Terms: type inferrence
Code
Playground
Expected behavior:
Both
reducedOneandreducedTwoshould be typed asPromise<string>Actual behavior:
reducedOneis typed as{}This issue only occurs when the function has a generic type. This works fine:
Playground