user8570495
user8570495

Reputation: 1835

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.

Upvotes: 38

Views: 20620

Answers (4)

Fenton
Fenton

Reputation: 250922

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

Upvotes: 34

Zhang Buzz
Zhang Buzz

Reputation: 11068

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.

Upvotes: 6

Jonathan Ramos
Jonathan Ramos

Reputation: 2161

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.

Upvotes: 6

Benny Code
Benny Code

Reputation: 54812

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.

Upvotes: 4

Related Questions