typescript/no-restricted-types Restriction
What it does
Disallow certain types from being used.
Why is this bad?
Some built-in types have aliases, while some types are considered dangerous or harmful. It's often a good idea to ban certain types to help with consistency and safety.
Examples
Given { "types": { "Foo": { "message": "Use Bar instead", "fixWith": "Bar" } } }:
Examples of incorrect code for this rule:
let value: Foo;Examples of correct code for this rule:
let value: Bar;Other examples of configuration option setups for this rule:
Banning the
Footype with just a message, no fixes or suggestions:{ "types": { "Foo": "UseOtherTypeinstead." } }Banning
Bartype with suggestion:{ "types": { "Bar": { "message": "Avoid usingBar.", "suggest": "BazQux" } } }Banning
Objecttype with a generic message:{ "types": { "Object": true } }
Configuration
This rule accepts a configuration object with the following properties:
types
type: object
default: {}
A mapping of type names to ban configurations.
How to use
To enable this rule in the CLI or using the config file, you can use:
oxlint --deny typescript/no-restricted-types{
"rules": {
"typescript/no-restricted-types": "error"
}
}