useNamespaceKeyword
Diagnostic Category: lint/suspicious/useNamespaceKeyword
Since: v1.0.0
Sources:
Require using the namespace
keyword over the module
keyword to declare TypeScript namespaces.
TypeScript historically allowed a code organization called namespace.
ECMAScript modules are preferred (import
/ export
).
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.
Note that TypeScript module
declarations to describe external APIs (declare module "foo" {}
) are still allowed.
See also: https://www.typescriptlang.org/docs/handbook/namespaces-and-modules.html
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-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 │