TypeScript-Handbook icon indicating copy to clipboard operation
TypeScript-Handbook copied to clipboard

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

Open Jamesernator opened this issue 6 years ago • 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)]))

Jamesernator avatar Apr 15 '19 06:04 Jamesernator