Is there any way to get warnings (not errors) for noImplicitAny noncompliance?
Asked Answered
W

3

9

I have a lot of code that I'm porting to Typescript with missing types. For now, I'd like my IDE (WebStorm) to just highlight places that need typing, and I'll slowly get them fixed up.

If tsconfig.json had a warning setting for noImplicitAny, that would be ideal. Another alternative would be a tslint rule, but I don't know if the tslint engine is up to this job.

Does anyone know of a way to achieve this?

Wilona answered 23/3, 2017 at 21:24 Comment(3)
The compiler will create (override) the js files even if it raises errors (unless the --noEmitOnError flag is used), so technically those are warnings...Panarabism
@NitzanTomer Yes, I know. I don't want to have to wade through dozens of these messages to find others of more import, on every compile.Wilona
If you're looking for a way to do this with TypeScript-ESLint, now that TSLint has been deprecated, see hereLimbic
A
0

Edit:

As antoine129 pointed out in the comments,there is actually no noImplicitAny eslint rule. I was thinking of no-explicit-any. One approach would be to havenoImplictAny on in the tsconfig and set no-explicit-any: "warn" in the .eslintrc, but you would have to add all the anys first.

OLD ANSWER (incorrect):

The Typescript ESLint plugin can do this. Since this question was posted, TSLint has been deprecated in favour of using ESLint with @typescript-eslint/eslint-plugin.

To get eslint warnings instead of compiler errors, you could turn the noImplicitAny flag off in tsconfig.json, and set noImplicitAny to "warn" in the rules section of your .eslintrc.

Anaglyph answered 30/7, 2019 at 0:34 Comment(2)
noImplicitAny is not an Eslint ruleIndraft
@antoine129 You're right. I can't delete this answer because it was accepted, but I updated it.Anaglyph
B
3

you can either enable noImplicitAny as true, or strict as true (would enable noImplicitAny and several other rules), in tsconfig.json.

Barnabe answered 5/9, 2019 at 8:13 Comment(0)
B
0

In your case, it is the IDE rather than the TypeScript language or compiler that you need to work on.

If your IDE allows you to set the level of warnings, you can tell it to make these informational. Otherwise, you'll need to flip/flop by switching on noImplicitAny while you are working on fixing your older code and the switching it back off again when you feel you have got far enough.

Borer answered 24/3, 2017 at 8:38 Comment(2)
Well... no. While IDE internal inspections are usually individually tweakable for severity, I've never seen an IDE where it allows one to tweak the severity of specific compiler errors. And it's really Typescript that's more wrong in this case; these would usually be considered compiler warnings, not errors.Wilona
Is the TypeScript compiler wrong? You have switched on the flag that says "don't allow implicit any types" and you are also annoyed that it does so? There is no option that does exactly what you want in the exact way you want it. Just use the option temporarily to discover and fix some instances until you can leave it on full time.Borer
A
0

Edit:

As antoine129 pointed out in the comments,there is actually no noImplicitAny eslint rule. I was thinking of no-explicit-any. One approach would be to havenoImplictAny on in the tsconfig and set no-explicit-any: "warn" in the .eslintrc, but you would have to add all the anys first.

OLD ANSWER (incorrect):

The Typescript ESLint plugin can do this. Since this question was posted, TSLint has been deprecated in favour of using ESLint with @typescript-eslint/eslint-plugin.

To get eslint warnings instead of compiler errors, you could turn the noImplicitAny flag off in tsconfig.json, and set noImplicitAny to "warn" in the rules section of your .eslintrc.

Anaglyph answered 30/7, 2019 at 0:34 Comment(2)
noImplicitAny is not an Eslint ruleIndraft
@antoine129 You're right. I can't delete this answer because it was accepted, but I updated it.Anaglyph

© 2022 - 2024 — McMap. All rights reserved.