prefer-namespace-keyword
Require using
namespace
keyword overmodule
keyword to declare custom TypeScript modules.
Extending "plugin:@typescript-eslint/stylistic"
in an ESLint configuration enables this rule.
Some problems reported by this rule are automatically fixable by the --fix
ESLint command line option.
TypeScript historically allowed a form of code organization called "custom modules" (module Example {}
), later renamed to "namespaces" (namespace Example
).
Namespaces are an outdated way to organize TypeScript code.
ES2015 module syntax is now preferred (import
/export
).
For projects still using custom modules / namespaces, it's preferred to refer to them as namespaces.
This rule reports when the module
keyword is used instead of namespace
.
This rule does not report on the use of TypeScript module declarations to describe external APIs (
declare module 'foo' {}
).
module.exports = {
"rules": {
"@typescript-eslint/prefer-namespace-keyword": "error"
}
};
Examples
- ❌ Incorrect
- ✅ Correct
module Example {}
namespace Example {}
declare module 'foo' {}
Options
This rule is not configurable.
When Not To Use It
If you are using the ES2015 module syntax, then you will not need this rule.