在Typescript中为单个行抑制未使用的属性警告

Roy*_*son 13 typescript

有没有办法让我的代码用ts-node编译,即使我的.ts文件的一行没有未使用的属性警告而没有"noUsedLocals": false在我的tsconfig.json文件中设置?

jma*_*eis 17

从TypeScript 2.6开始,您可以使用// @ts-ignore.

一个// @ts-ignore评论抑制了以下行发起的所有错误.建议练习在@ts-ignore后面的注释的其余部分解释哪个错误被抑制.

请注意,此评论仅抑制错误报告,我们建议您非常谨慎地使用此评论.

source(发行说明TypeScript 2.6

如果错误是tslint错误,那么您可以使用它来禁用它们

// tslint:disable-next-line
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅https://palantir.github.io/tslint/usage/rule-flags/.

  • 仅供参考 - 我的 eslint 建议使用 `// @ts-expect-error` 来优先忽略 (4认同)

Tre*_*vor 8

现在可以使用_未使用的参数.

function myFunc(_, b: string) {}
function otherFunc(_, _1, c: string) {} // multiple unsused
Run Code Online (Sandbox Code Playgroud)

https://github.com/Microsoft/TypeScript/issues/9458