简体   繁体   中英

what is the meaning of tslint: “Warning: The 'no-use-before-declare' rule requires type information”?

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.

Update ! Since this question was asked, the --type-check flag has been deprecated so you should be able use:

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.

tslint --type-check --project tslint.json src/**/**.ts

If you see this warning in VSCode, just delete this rule from tslint.json , as the README file in vscode-tslint plugin says:

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.

With TSLint v5.10.0 and above, you need to point TSLint to your TypeScript configuration file. You can do that by using the --project flag:

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 .

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 .

The rule is discouraged, since modern TypeScript do not use it and is slow to compute. Acording to this page :

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM