noNamespace
Summary
Section titled Summary- Rule available since:
v1.0.0
- Diagnostic Category:
lint/style/noNamespace
- This rule doesn’t have a fix.
- The default severity of this rule is information.
- Sources:
- Same as
@typescript-eslint/no-namespace
- Same as
Description
Section titled DescriptionDisallow the use of TypeScript’s namespace
s.
Namespaces are an old way to organize your code in TypeScript.
They are not recommended anymore and should be replaced by ES6 modules
(the import
/export
syntax).
Examples
Section titled ExamplesInvalid
Section titled Invalidmodule foo {}
code-block.ts:1:1 lint/style/noNamespace ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ TypeScript’s namespaces are an outdated way to organize code.
> 1 │ module foo {}
│ ^^^^^^^^^^^^^
2 │
ℹ Prefer the ES6 modules (import/export) over namespaces.
declare module foo {}
code-block.ts:1:9 lint/style/noNamespace ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ TypeScript’s namespaces are an outdated way to organize code.
> 1 │ declare module foo {}
│ ^^^^^^^^^^^^^
2 │
ℹ Prefer the ES6 modules (import/export) over namespaces.
namespace foo {}
code-block.ts:1:1 lint/style/noNamespace ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ TypeScript’s namespaces are an outdated way to organize code.
> 1 │ namespace foo {}
│ ^^^^^^^^^^^^^^^^
2 │
ℹ Prefer the ES6 modules (import/export) over namespaces.
declare namespace foo {}
code-block.ts:1:9 lint/style/noNamespace ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ TypeScript’s namespaces are an outdated way to organize code.
> 1 │ declare namespace foo {}
│ ^^^^^^^^^^^^^^^^
2 │
ℹ Prefer the ES6 modules (import/export) over namespaces.
Valid
Section titled Validimport foo from 'foo';export { bar };
declare global {}
declare module 'foo' {}
How to configure
Section titled How to configure{ "linter": { "rules": { "style": { "noNamespace": "error" } } }}