typescript tslint 的含义是什么:“警告:'no-use-before-declare' 规则需要类型信息”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46715843/
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
what is the meaning of tslint: "Warning: The 'no-use-before-declare' rule requires type information"?
提问by user8570495
What is the meaning of tslint: "Warning: The 'no-use-before-declare' rule requires type information."? I did some basic googling but I'm not clear on what this means or its implications.
tslint 是什么意思:“警告:'no-use-before-declare' 规则需要类型信息。”?我做了一些基本的谷歌搜索,但我不清楚这意味着什么或其含义。
采纳答案by Fenton
Update! Since this question was asked, the --type-check
flag has been deprecated so you should be able use:
更新!自从提出这个问题以来,该--type-check
标志已被弃用,因此您应该可以使用:
tslint --project tsconfig.json src/**/**.ts
Original answer below.
原答案如下。
I believe that this means you can't enable the no-use-before-declare
rule unless you run with the --type-check
and the --project
flags. It must depend on something that happens when those flags are passed in order to determine rule violations.
我相信这意味着no-use-before-declare
除非您使用--type-check
和--project
标志运行,否则您无法启用该规则。它必须取决于传递这些标志时发生的事情,以确定违反规则的情况。
tslint --type-check --project tslint.json src/**/**.ts
回答by Zhang Buzz
If you see this warning in VSCode, just delete this rule from tslint.json
, as the READMEfile in vscode-tslint
plugin says:
如果您在 VSCode 中看到此警告,只需从 中删除此规则tslint.json
,如插件中的README文件所述vscode-tslint
:
Since tslint version 5 the rule no-unused-variable requires type information. Rules with type information are currently not supported by vscode-tslint, pls see issue #70. The recommended work around is to enable the TypeScript compiler options noUnusedLocals and noUnusedParameters in your tsconfig.json file.
从 tslint 版本 5 开始,规则 no-unused-variable 需要类型信息。vscode-tslint 目前不支持带有类型信息的规则,请参阅问题 #70。建议的解决方法是在 tsconfig.json 文件中启用 TypeScript 编译器选项 noUnusedLocals 和 noUnusedParameters。
回答by Benny Neugebauer
With TSLint v5.10.0and above, you need to point TSLint to your TypeScript configurationfile. You can do that by using the --project
flag:
使用TSLint v5.10.0及更高版本,您需要将 TSLint 指向您的TypeScript 配置文件。您可以通过使用--project
标志来做到这一点:
tslint --project tsconfig.json --config tslint.json \"src/**/*.ts\"
Be careful, because it's easy to mix up tsconfig.json
and tslint.json
as some users already experienced.
小心,因为它很容易混淆,tsconfig.json
而且tslint.json
一些用户已经体验过。
All TSLint CLI options are documented here. The usage of --type-check
is not needed anymore as it got deprecated in TSLint v5.8.0.
此处记录了所有 TSLint CLI 选项。的使用--type-check
,不再需要为它得到了弃用TSLint V5.8.0。
回答by Jonathan Ramos
The rule is discouraged, since modern TypeScript do not use it and is slow to compute. Acording to this page:
不鼓励使用该规则,因为现代 TypeScript 不使用它并且计算速度很慢。根据此页面:
This rule is primarily useful when using the var keyword since the compiler will automatically detect if a block-scoped let and const variable is used before declaration. Since most modern TypeScript doesn't use var, this rule is generally discouraged and is kept around for legacy purposes. It is slow to compute, is not enabled in the built-in configuration presets, and should not be used to inform TSLint design decisions.
这条规则主要在使用 var 关键字时有用,因为编译器会在声明之前自动检测是否使用了块范围的 let 和 const 变量。由于大多数现代 TypeScript 不使用 var,因此通常不鼓励此规则并保留用于遗留目的。它计算缓慢,未在内置配置预设中启用,不应用于通知 TSLint 设计决策。