The banned type can either be a type name literal (Foo), a type name with generic parameter instantiations(s) (Foo<Bar>), or the empty object literal ({}).
{
"@typescript-eslint/ban-types": ["error", {
"types": {
// report usages of the type using the default error message
"Foo": null,
// add a custom message to help explain why not to use it
"Bar": "Don't use bar!",
// add a custom message, AND tell the plugin how to fix it
"String": {
"message": "Use string instead",
"fixWith": "string"
}
"{}": {
"message": "Use object instead",
"fixWith": "object"
}
}
}]
}
By default, this rule includes types which are likely to be mistakes, such as String and Number. If you don't want these enabled, set the extendDefaults option to false:
{
"@typescript-eslint/ban-types": ["error", {
"types": {
// add a custom message, AND tell the plugin how to fix it
"String": {
"message": "Use string instead",
"fixWith": "string"
}
},
"extendDefaults": false
}]
}