deno.com

no-namespace

注意: 此规则是 recommended 规则集的一部分。
deno.json 中启用完整规则集:
{
  "lint": {
    "rules": {
      "tags": ["recommended"]
    }
  }
}
使用 Deno CLI 启用完整规则集:
deno lint --rules-tags=recommended

禁止在 TypeScript 代码中使用 namespacemodule 关键字。

namespacemodule 都被认为是过时的关键字来组织代码。相反,通常更推荐使用 ES2015 模块语法(例如 import/export)。

然而,此规则仍然允许在以下两种情况下使用这些关键字:

  • 它们与 declare 关键字一起用于定义 "ambient" 命名空间
  • 它们写在 TypeScript 的类型定义文件中:.d.ts

无效:

// foo.ts
module mod {}
namespace ns {}
// bar.d.ts
// 在 `.d.ts` 中允许使用 `module` 和 `namespace` 关键字

有效:

// foo.ts
declare global {}
declare module mod1 {}
declare module "mod2" {}
declare namespace ns {}
// bar.d.ts
module mod1 {}
namespace ns1 {}
declare global {}
declare module mod2 {}
declare module "mod3" {}
declare namespace ns2 {}

你找到需要的内容了吗?

隐私政策