在 Typescript 中为单个行抑制未使用的属性警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51385041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Suppress unused property warning in Typescript for individual line
提问by Roymunson
Is there a way to let my code compile with ts-node even if there is unused property warnings in one line of my .ts
file withoutsetting "noUsedLocals": false
in my tsconfig.json
file?
有没有办法让我的代码用 ts-node 编译,即使我的.ts
文件的一行中有未使用的属性警告而不"noUsedLocals": false
在我的tsconfig.json
文件中设置?
回答by jmattheis
Since TypeScript 2.6 you can suppress errors with // @ts-ignore
.
从 TypeScript 2.6 开始,您可以使用// @ts-ignore
.
A
// @ts-ignore
comment suppresses all errors that originate on the following line. It is recommended practice to have the remainder of the comment following @ts-ignore explain which error is being suppressed.Please note that this comment only suppresses the error reporting, and we recommend you use this comments very sparingly.
一个
// @ts-ignore
评论抑制了以下行发起的所有错误。建议的做法是让 @ts-ignore 后面的评论说明正在抑制哪个错误。请注意,此注释仅抑制错误报告,我们建议您非常谨慎地使用此注释。
source (release notes TypeScript 2.6
If the error is an tslint error then you can disable them with
如果错误是 tslint 错误,那么您可以禁用它们
// tslint:disable-next-line
See https://palantir.github.io/tslint/usage/rule-flags/for more information.
有关更多信息,请参阅https://palantir.github.io/tslint/usage/rule-flags/。
回答by Trevor
It is now possible to use _
for unused params.
现在可以_
用于未使用的参数。
function myFunc(_, b: string) {}
function otherFunc(_, _1, c: string) {} // multiple unsused