typescript/ban-types Pedantic
作用
此规则禁止某些特定类型,并且可以建议替代方案。请注意,它并不禁止使用对应的运行时对象。
WARNING
此规则已弃用,并将在未来版本中移除。
请优先使用以下替代规则:
typescript/no-empty-object-typetypescript/no-unsafe-function-typetypescript/no-wrapper-object-typestypescript/no-restricted-types(用于自定义类型禁止)
为什么这不好?
某些内置类型有别名,而某些类型则被认为是危险或有害的。通常,禁止某些类型有助于保持一致性和安全性。
示例
以下是此规则的错误代码示例:
typescript
let foo: String = "foo";
let bar: Boolean = true;以下是此规则的正确代码示例:
typescript
let foo: string = "foo";
let bar: boolean = true;如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"typescript/ban-types": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"typescript/ban-types": "error",
},
});bash
oxlint --deny typescript/ban-types版本
此规则在 v0.0.14 中添加。
