Skip to main content

prefer-namespace-keyword

Require using namespace keyword over module keyword to declare custom TypeScript modules.

🔧

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' {}).

.eslintrc.cjs
module.exports = {
"rules": {
"@typescript-eslint/prefer-namespace-keyword": "error"
}
};

Examples

module Example {}

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.

Further Reading

Resources