I get an error
Type '(number | undefined)[]' is not assignable to type 'number[]'.
when I write
const nums: number[] = [...'a'.matchAll(/a/g)].map(match => match.index);
but MDN doesn't say anything about this property being optional. Is this a bug or am I missing something?
CodePudding user response:
It's a bug in TypeScript; the issue has been reported in 2020. For now, you can safely assert that match.index
is a number
.