【发布时间】:2019-04-24 12:31:20
【问题描述】:
我正在解构正则表达式匹配的结果
function getStuffIWant(str: string): string {
const [
fullMatch, // [ts] 'fullMatch' is declared but its value is never read.
stuffIWant,
] = str.match(/1(.*)2/);
return stuffIWant;
}
getStuffIWant("abc1def2ghi");
正如评论所指出的,fullMatch 从未使用过,TSC 想让我知道。 有没有办法在不全面关闭未使用检查的情况下抑制此错误?
我也尝试将数组解包为对象:
const {
1: stuffIWant, // Unexpected SyntaxError: Unexpected token :
} = str.match(/1(.*)2/);
【问题讨论】: