小编Bla*_*e H的帖子

忽略打字稿中解构的多个结果

我正在使用打字稿解构,如下所示:

const props = new Map<User, [Name, Age, Location, Gender]>();
props.set(bill, [n, a, l, g]);

// ...

// Want to access location and gender of bill.
const [n, a, l, g] = props.get(bill);
console.log(l + g);
Run Code Online (Sandbox Code Playgroud)

但这违反了noUnusedLocals编译器选项,所以我真正想要的是:

const [_, _, l, g] = props.get(bill);
Run Code Online (Sandbox Code Playgroud)

但这违反了块作用域变量(两个名为 的变量_)的重新声明。

处理这个问题的最佳方法是什么?也许解构在这里只是错误的选择。

destructuring redeclaration typescript tsc

5
推荐指数
1
解决办法
1504
查看次数

标签 统计

destructuring ×1

redeclaration ×1

tsc ×1

typescript ×1