Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bypass warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any

We have a strict zero lint issues policy. This means all errors and warnings need to be fixed.

Facing this lint error in our React typescript project:

warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any

Searched on Google and on the lint website. I didn't find a solution as such!

Tried this: // eslint:@typescript-eslint/no-explicit-any: "off" which is not working

Does anyone know how to bypass this eslint rule in a React typescript project?

like image 438
xameeramir Avatar asked Oct 19 '19 18:10

xameeramir


People also ask

How do I disable TypeScript ESLint?

If you are using ESLint and you need to disable the next line, use this code: eslint-disable-next-line.

What is no explicit any?

Rule DetailsThis rule doesn't allow any types to be defined. It aims to keep TypeScript maximally useful. TypeScript has a compiler flag for --noImplicitAny that will prevent an any type from being implied by the compiler, but doesn't prevent any from being explicitly used.


2 Answers

Something that works for me when trying to bypass the same rule, specially for overloading methods is to use: // eslint-disable-next-line if you can simply just add a comment right above the line with the issue.

Or you can ignore the rule for just a section of the code by /* eslint-disable rule-name */ your-block-of-code /* eslint-enable rule-name */ The comments here must be block comments.

like image 157
akaizn Avatar answered Sep 24 '22 06:09

akaizn


Can you use unknown? e.g. HttpResponse<unknown>

like image 40
Sean Avatar answered Sep 22 '22 06:09

Sean