typescript/no-wrapper-object-types Correctness
它的作用
禁止使用包装对象类型。
为什么这不好?
包装对象类型是在全局作用域中定义的、不是原始类型的类型。这些类型不建议在 TypeScript 代码中使用。
示例
以下是此规则的错误代码示例:
ts
let myBigInt: BigInt;
let myBoolean: Boolean;
let myNumber: Number;
let myString: String;
let mySymbol: Symbol;
let myObject: Object = "由 TypeScript 允许";以下是此规则的正确代码示例:
ts
let myBigint: bigint;
let myBoolean: boolean;
let myNumber: number;
let myString: string;
let mySymbol: symbol;
let myObject: object = "Type 'string' is not assignable to type 'object'.";如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"typescript/no-wrapper-object-types": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"typescript/no-wrapper-object-types": "error",
},
});bash
oxlint --deny typescript/no-wrapper-object-types版本
此规则于 v0.8.0 中添加。
