src/content/docs/linter/rules/no-restricted-types.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="TypeScript and TSX" icon="seti:typescript"> ## Summary - Rule available since: `v1.9.0` - Diagnostic Category: [`lint/style/noRestrictedTypes`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule has a [**safe**](/linter/#safe-fixes) fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Same as [`@typescript-eslint/no-restricted-types`](https://typescript-eslint.io/rules/no-restricted-types){
"linter": {
"rules": {
"style": {
"noRestrictedTypes": "error"
}
}
}
}
Disallow user defined types.
This rule allows you to specify type names that you don’t want to use in your application.
To prevent use of commonly misleading types, you can refer to noBannedTypes
Use the options to specify additional types that you want to restrict in your source code.
{
"linter": {
"rules": {
"style": {
"noRestrictedTypes": {
"options": {
"types": {
"Foo": {
"message": "Only bar is allowed",
"use": "bar"
},
"OldAPI": "Use NewAPI instead"
}
}
}
}
}
}
}
In the example above, the rule will emit a diagnostics if Foo or OldAPI are used.