简中文档

ban-types

NOTE: this rule is part of the 推荐 rule set.
Enable full set in deno.json:
{
  "lint": {
    "rules": {
      "tags": ["推荐"]
    }
  }
}
Enable full set using the Deno CLI:
deno lint --rules-tags=推荐
This rule can be explictly included to or excluded from the rules present in the current tag by adding it to the include or exclude array in deno.json:
{
  "lint": {
    "rules": {
      "include": ["ban-types"],
      "exclude": ["ban-types"]
    }
  }
}

禁止使用原始包装对象(例如 String 这个对象是 string 原始类型的包装),以及不明确的 Function 类型和误解的 Object 类型。

原始包装对象的使用情况非常少见,更多的情况是使用原始类型时出现错误。你也不能将原始包装对象赋值给原始类型,这会导致后续的类型问题。作为参考,TypeScript 手册 也表示我们不应使用这些包装对象。

对于 Function,最好明确指定整个函数签名,而不是使用模糊的 Function 类型,这样不会给你提供函数的类型安全。

最后,Object{} 意味着“任何非空值”,而不是“任何对象类型”。object 是表示“任何对象类型”的不错选择。

无效:

let a: Boolean;
let b: String;
let c: Number;
let d: Symbol;
let e: Function;
let f: Object;
let g: {};

有效:

let a: boolean;
let b: string;
let c: number;
let d: symbol;
let e: () => number;
let f: object;
let g: Record<string, never>;

你找到了你需要的东西吗?

编辑此页面
隐私政策