不允许使用某些类型。
支持配置以下选项:
type Options = {
types: {
[key: string]: boolean | string | { message: string, fixWith: string } | null;
};
extendDefaults: boolean;
} 示例:
"@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
},
] // 类型小写保持一致
const str: string = 'foo';
const bool: boolean = true;
const num: number = 1;
const bigInt: bigint = 1n;
// 使用正确的函数类型
const func: () => string = () => 'hello';
export { str, bool, num, bigInt, func };