ChatGPT解决这个技术问题 Extra ChatGPT

Disable typescript-eslint plugin rule (no-explicit-any) with inline comment

I have an eslint error that comes from the @typescript-eslint plugin.

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

This is the no-implicit-any rule. In just one file I want to disable that rule with a comment at the top of the file.

The compiler complains if I just try a standard eslint disable:

/* eslint-disable  no-explicit-any */

Definition for rule 'no-explicit-any' was not found.eslint(no-explicit-any)

I've tried to find documentation on inline rules for the TS plugin, but without much luck. I've also tried various combinations like these:

/* typescript-eslint-disable no-implicit-any */
/* typescript-eslint: disable no-implicit-any */
/* typescript-eslint: disable noImplicitAny */
/* typescript-eslint-disable @typescript-eslint/no-implicit-any */

There are no eslint complaints but the error will not disappear.

How do I disable an typescript-eslint rule?

It would probably be good to update this question to read no-explicit-any every time, since you sometimes say no-IMPLICIT-any, even though that's a tsconfig option, not an ESLint rule.

a
abdelhedi hlel

add this to the .eslintrc (tslintrc) file :

rules: {
    "@typescript-eslint/no-explicit-any": "off"
  },

The OP write "In just one file I want to disable that rule with a comment at the top of the file."
It is not OP request
It might be necessary to restart the IDE
Thank you Sir.. I was fighting that warning for days..
This has no effect in my project. Did something change?
c
cham

The correct syntax is like this:

/* eslint-disable  @typescript-eslint/no-explicit-any */

So that you directly reference the plugin via eslint.


M
Meredith Murfin

If you're attempting to disable a rule on the next line only (rather than for an entire file), adding this comment directly above the line to ignore will work:

// eslint-disable-next-line  @typescript-eslint/no-explicit-any