Search code examples
typescripteslinttypingtypescript-eslint

eslint ban types rule with warning or error based on config


Is there a way to configure @typescript-eslint/ban-types in a way that will throw errors for the default rules and warnings for the additional/custom ones?

Example: I want types like String and Object to throw an error which is default behavior. Additionally, I don't want people to use UntypedFormGroup which should throw a warning only.

I tried it with the following config:

"@typescript-eslint/ban-types": [
  "warn",
  {
    "types": {
      "UntypedFormGroup": "Please use FormGroup which is a generic and helps you write better code.",
      ...
    },
    "extendDefaults": true
  }
],

The problem: this will only output warnings for ALL of the default types, but not only my custom ones. How can I change this to match the example's behavior?


Solution

  • In the meantime, I found out that this isn't possible and probably won't be implemented. https://github.com/eslint/eslint/issues/14061