useNamespaceKeyword
诊断类别:lint/suspicious/useNamespaceKeyword
¥Diagnostic Category: lint/suspicious/useNamespaceKeyword
自从:v1.0.0
¥Since: v1.0.0
来源:
¥Sources:
要求使用 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
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
¥Related links