133

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?

cham
  • 8,666
  • 9
  • 48
  • 69
  • 1
    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. – Christian Jensen Apr 20 '21 at 18:53

4 Answers4

176

add this to the .eslintrc (tslintrc) file :

rules: {
    "@typescript-eslint/no-explicit-any": "off"
  },
abdelhedi hlel
  • 2,903
  • 1
  • 16
  • 20
156

The correct syntax is like this:

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

So that you directly reference the plugin via eslint.

cham
  • 8,666
  • 9
  • 48
  • 69
  • 4
    This should be the accepted answer since it directly addresses OP's question about using at the top of the file, but other viewers here might want to note that unless you *really* want to disable linting for the entire file, you probably want to go with the [other answer](https://stackoverflow.com/a/66659083/758334). – Subfuzion Sep 19 '22 at 15:07
83

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
Meredith Murfin
  • 841
  • 4
  • 4
  • You can also disable on the same line with e.g. ` // eslint-disable-line @typescript-eslint/no-explicit-any -- optional reason goes here` – ShadSterling Jan 18 '23 at 01:00
0

You may also come across the following syntax, so you would update with value of 0 if it is set to 1:

'@typescript-eslint/no-explicit-any': 0,
Abdush Samad Miah
  • 186
  • 1
  • 8
  • 19