Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 878
user8570495 Avatar asked Oct 12 '17 17:10

user8570495


4 Answers

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
like image 197
Fenton Avatar answered Oct 12 '22 01:10

Fenton


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.

like image 30
Jonathan Ramos Avatar answered Oct 12 '22 01:10

Jonathan Ramos


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.

like image 29
Zhang Buzz Avatar answered Oct 12 '22 02:10

Zhang Buzz


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.

like image 25
Benny Neugebauer Avatar answered Oct 12 '22 02:10

Benny Neugebauer