no-restricted-types
Configuration
Rule Details
Disallow specified types. The rule reports any usage of a type whose name matches a key in the configured types map. Names are compared after stripping all whitespace, so a source-side Banned<A, B> matches a configured key of Banned<A,B> (and a configured key of NS.Banned matches a source-side NS.Banned).
The rule recognizes these type-syntax forms:
- Primitive type keywords (
bigint,boolean,never,null,number,object,string,symbol,undefined,unknown,void). - Type references — both bare (
Banned,NS.Banned) and parameterized (Banned<A>,NS.Banned<A>). - The empty tuple type
[]. - The empty type literal
{}. - Heritage references —
class X implements Bannedandinterface X extends Banned.
Each entry in types pairs a type name with one of:
true— ban with the default message.falseornull— explicitly do not ban this name.- A
string— ban with the string appended to the default message. - An object
{ message?: string, fixWith?: string, suggest?: string[] }— ban with an extra message, an optional auto-fix replacement, and/or one or more editor suggestions.
Examples of incorrect code for this rule with { "types": { "Banned": "Use Ok instead." } }:
Examples of correct code for this rule with { "types": { "Banned": "Use Ok instead." } }:
Examples of incorrect code for this rule with { "types": { "Banned": { "fixWith": "Ok", "message": "Use Ok instead." } } }:
The auto-fix rewrites the type reference to Ok.
Examples of incorrect code for this rule with { "types": { "[]": "Use unknown[] instead." } }: