microsoft/TypeScript-Handbook

Add (another) simpler example of higher order function inference to TypeScript 3.4 release notes

Jamesernator opened this issue · 0 comments

The release notes for 3.4 have quite a heavy-weight example of higher order function inference where a considerably simpler example would probably help more people I understand it.

The simplest example I can think of (that I often hit before 3.4) would be this:

const numbers = [1,2,3,4,5]
// Previously: '(string | number)[][]' is not assignable to parameter of type 'ReadonlyArray<[{}, {}]>'
// Now: s is correctly inferred as Map<number, string>
const s = new Map(numbers.map(x => [x, String(x)]))