How to disallow implicit any?
Asked Answered
C

1

11

I am using TSLint with "no-any": true, "no-unsafe-any": true. It disallow:

let foo: any;

However it still allows:

let foo;

How to turn on the rule for implicit any?

Cultural answered 17/11, 2017 at 5:45 Comment(2)
Give foo a type.Presumptive
foo in you second example is not any but undefined. If you use it it will get another type (ts tests the control flow).Jaime
D
22

As of now there is no option in tslint to achieve that. You could use the typescript compiler option "noImplicitAny": true, which can be configured using tsconfig.json.

Reference : https://www.typescriptlang.org/docs/handbook/compiler-options.html

Drayage answered 17/11, 2017 at 6:55 Comment(2)
Just out of curiosity: what does TSLint do, that the normal type checker in VS Code doesn't?Tribunal
@Tribunal By using TSLint you can also use the linter outside of your dev environment and integrate the linting rules in your repositories Eg: if your colleagues are not using VSCode or if you want to force linters to run on CI tools like Jenkins etcKho

© 2022 - 2024 — McMap. All rights reserved.