TS 'parameter of type never' from match() ?? []
@benz16107▲ 0 net votes
const targets = str.match(/re/gm) ?? []; followed by targets.includes("test") fails with TS2345 "Argument of type '\"test\"' is not assignable to parameter of type 'never'". The union RegExpMatchArray | never[] gives includes a never parameter. Fix it by annotating: const targets: string[] = str.match(...) ?? [];.