useNamespaceKeyword
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/suspicious/useNamespaceKeyword¥Diagnostic Category:
lint/suspicious/useNamespaceKeyword -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则包含 safe 修复程序。
¥This rule has a safe fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
来源:
¥Sources:
¥How to configure
{ "linter": { "rules": { "suspicious": { "useNamespaceKeyword": "error" } } }}¥Description
要求使用 namespace 关键字而不是 module 关键字来声明 TypeScript 命名空间。
¥Require using the namespace keyword over the module keyword to declare TypeScript namespaces.
TypeScript 历史上允许一种称为命名空间的代码组织。首选 ECMAScript 模块 (import / export).
¥TypeScript historically allowed a code organization called namespace.
ECMAScript modules are preferred (import / export).
对于仍在使用命名空间的项目,最好使用 namespace 关键字而不是 module 关键字。module 关键字已弃用,以避免与通常称为模块的 ECMAScript 模块混淆。
¥For projects still using namespaces, it’s preferred to use the namespace keyword instead of the module keyword.
The module keyword is deprecated to avoid any confusion with the ECMAScript modules which are often called modules.
请注意,仍然允许使用 TypeScript module 声明来描述外部 API(declare module "foo" {})。
¥Note that TypeScript module declarations to describe external APIs (declare module "foo" {}) are still allowed.
另请参阅:https://ts.nodejs.cn/docs/handbook/namespaces-and-modules.html
¥See also: https://ts.nodejs.cn/docs/handbook/namespaces-and-modules.html
¥Examples
¥Invalid
module Example {}code-block.ts:1:1 lint/suspicious/useNamespaceKeyword FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Use the namespace keyword instead of the outdated module keyword.
> 1 │ module Example {}
│ ^^^^^^
2 │
ℹ The module keyword is deprecated to avoid any confusion with the ECMAScript modules which are often called modules.
ℹ Safe fix: Use namespace instead.
1 │ - module·Example·{}
1 │ + namespace·Example·{}
2 2 │
¥Valid
namespace Example {}declare module "foo" {}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号