what is the meaning of tslint: "Warning: The 'no-use-before-declare' rule requires type information"?
Asked Answered
C

4

38

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.

Cage answered 12/10, 2017 at 17:44 Comment(0)
S
34

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
Sever answered 12/10, 2017 at 17:53 Comment(4)
looks like that rule is mainly a validation check when using the var keyword: palantir.github.io/tslint/rules/no-use-before-declare if the var-keyword-forbidden rule is enabled then it seems that this rule can be disabled right?Cage
Precisely - TypeScript already warns you about let and const violations. The only reason it doesn't warn you about it with var is because variables declared with var get hoisted, so they are technically declared before they used.Sever
Note: --type-check is deprecated. You only need --project to enable rules which need type information (TSLint v5.10.0).Ilysa
It should be tslint --project tsconfig.json … not tslint.json.Brod
W
6

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.

Willhite answered 29/5, 2018 at 16:25 Comment(0)
B
6

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.

Barns answered 10/9, 2018 at 6:13 Comment(0)
I
4

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.

Ilysa answered 12/5, 2018 at 14:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.