Skip to main content

TS Errors

Property 'forEach' does not exist on type 'IterableIterator<RegExpMatchArray\>'.ts(2339)

you forgot to spread into array first for the match result before calling .forEach!

const spread_into_array_first = [...input_str.matchAll(__some_regexp)].forEach(x => console.log("now it is properly iterating!"))

Type 'RegExpMatchArray | null' must have a 'Symbol.iterator' method that returns an iterator.ts(2488)

this might work in vanilla JS but TS will warn for exceptions when there is no RegExp match where you cannot iterate on a null result.

bad fix 1: @ts-ignore
bad fix 2: ! assertion at end
better fix 1:

References