Given this slightly artificial example:
['List', 'Of', 'Names']
.map((name, index) => [name, index % 2])
.map(([name, num]) => );
why is name and num in the last line of type string | number
obviously inferred as an Array of strings and numbers and do any of you know if there is a way to use type inference so that name is a string and num is a number respectively?
You can use a const assertion:
['List', 'Of', 'Names']
.map((name, index) => [name, index % 2] as const) // insert `as const` here
.map(([name, num]) => { }); // name: string, num: number
Take a look at the playground sample.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With