Skip to content

Ban Types

Error
small-rules/ban-types

Ban configured TypeScript utility types, defaulting to Omit in favor of Except.

Rationale

Omit<T, K> doesn’t check that the keys you name exist on T. Misspell one, or rename the property later, and Omit keeps compiling while leaving the property in. Except from type-fest requires K to be a key of T, so the same mistake is a type error.

That’s the only type banned by default. Use bannedTypes to add your own: an array bans the names outright, and an object maps each banned name to the type you’d rather people reach for. Your entries are added to the default, so Omit stays banned.

Diagnostic Messages

bannedType
Type '{{typeName}}' is banned by project configuration. Use the project-preferred alternative for this type.
bannedTypeWithReplacement
Type '{{typeName}}' is banned. Use '{{replacementName}}' instead.

Configuration

This rule accepts one options object after the severity.

bannedTypesOptional

Array of banned type names or an object mapping banned type names to preferred replacement names.

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/ban-types": [
"error",
{
"bannedTypes": {
"Omit": "Except"
}
}
]
}
}

Examples

Disallowed Omit utility type
type User = {
readonly name: string;
readonly password: string;
};
type HiddenUser = Omit<User, "password">;
Allowed Pick utility type
type User = {
readonly name: string;
};
type ActiveUser = Pick<User, "name">;