【发布时间】:2021-05-05 11:11:17
【问题描述】:
我正在尝试仅过滤 RegExp 表达式并得到一个错误。
const arr = ['test', '/test/', /test/, /test/g];
const regs: RegExp[] = arr.filter(str => str instanceof RegExp);
Type '(string | RegExp)[]' is not assignable to type 'RegExp[]'.
Type 'string | RegExp' is not assignable to type 'RegExp'.
Type 'string' is not assignable to type 'RegExp'.
如何通过仅获取RegExp 的列表来避免此类错误?
【问题讨论】:
标签: typescript typescript-typings