Disallow certain types.
This rule supports the following options:
type Options = {
types: {
[key: string]: boolean | string | { message: string, fixWith: string } | null;
};
extendDefaults: boolean;
} Example:
"@typescript-eslint/ban-types": [
"error",
{
"types": {
"String": true,
"Number": false,
"MyType": "Do not use 'MyType'",
"MyTypeWithFix": {
"message": "Do not use 'MyTypeWithFix', use 'MyType' instead",
"fixWith": "MyType"
}
},
"extendDefaults": true
},
] // Type casing should remain consistent in lowercase.
const str: string = 'foo';
const bool: boolean = true;
const num: number = 1;
const bigInt: bigint = 1n;
// Use the correct function types.
const func: () => string = () => 'hello';
export { str, bool, num, bigInt, func }; // Type casing should remain consistent in lowercase.
const str: String = 'foo';
const bool: Boolean = true;
const num: Number = 1;
const bigInt: BigInt = 1n;
// Use the correct function types.
const func: Function = () => 'hello';
export { str, bool, num, bigInt, func }; plugin:@typescript-eslint/all
For details about how to configure Code Linter check rules, see Code Linter.