Bla*_*e H 5 destructuring redeclaration typescript tsc
我正在使用打字稿解构,如下所示:
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)
但这违反了块作用域变量(两个名为 的变量_)的重新声明。
处理这个问题的最佳方法是什么?也许解构在这里只是错误的选择。
根据 ES6文档,你可以这样做:
const [, , l, g] = props.get(bill);
Run Code Online (Sandbox Code Playgroud)
您可以在这里找到一个最小的工作示例。
| 归档时间: |
|
| 查看次数: |
1504 次 |
| 最近记录: |