Tho*_*ggi 6 tuples typescript eslint tslint
我有一行代码,如下所示:
const [full, text, url] = markdownLink.exec(match) || [null, null, '']
Run Code Online (Sandbox Code Playgroud)
但是我没有使用full,并且 linter 给了我一个警告。
第 28 行:“full”被赋值但从未使用过
我想像这样声明元组,但我不需要full。有没有一种语法方法可以通过跳过完整来解决这个问题?
此警告是因为您的数组解构正在执行一些操作,例如full = null;稍后不会使用的操作。
数组解构非常性感,但并不总是解决方案。在您的情况下,只需以经典方式访问数组即可。
const arr = markdownLink.exec(match) || [null, null, ''];
const text = arr[1];
const url = arr[2];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1655 次 |
| 最近记录: |