It can sometimes be useful to ban specific types from being used in type annotations. For example, a project might be migrating from using one type to another, and want to ban references to the old type.
This rule can be configured to ban a list of specific types and can suggest alternatives. Note that it does not ban the corresponding runtime objects from being used.
An object whose keys are the types you want to ban, and the values are error messages.
The type can either be a type name literal (OldType
) or a a type name with generic parameter instantiation(s) (OldType<MyArgument>
).
{
"@typescript-eslint/no-restricted-types": [
"error",
{
"types": {
"OldType": "Don't use OldType because it is unsafe",
"OldAPI": {
"message": "Use NewAPI instead",
"fixWith": "NewAPI",
},
"SoonToBeOldAPI": {
"message": "Use NewAPI instead",
"suggest": ["NewAPIOne", "NewAPITwo"],
},
},
},
],
}
If you have no need to ban specific types from being used in type annotations, you don't need this rule.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4