我试图在GitHub上输入任何内容之前确定这是否是一个错误.
与noUnusedParameters启用,打字稿编译器将错误的东西,如:
const foo = ['one', 'two', 'three'];
foo.forEach((item: string, index: number) => {
// do something just with index, ignoring item
});
Run Code Online (Sandbox Code Playgroud)
与error TS6133: 'item' is declared but never used.不过,虽然它没有具体使用时,它被用在了第二个参数的forEach迭代函数的索引.
我错过了什么吗?
Nit*_*mer 13
没有必要提交问题,因为已存在一个问题:使用--noUnusedParameters我如何跳过未使用的参数.
tl; dr:
您可以通过在下划线前面添加不感兴趣的参数来跳过此错误:
const foo = ['one', 'two', 'three'];
foo.forEach((_item: string, index: number) => {
console.log(index);
});
Run Code Online (Sandbox Code Playgroud)
编译好.