Skip to content

no-namespace

Reports a namespace N {} or module N {} declaration, also a dotted namespace A.B {}. declare module "x", declare global, and any namespace in a .d.ts file are not reported.

A TypeScript namespace is an older way to group code that does not exist in JavaScript: it compiles to an object built by a function, cannot be tree-shaken well and is not understood by tools that only strip types. ES modules do the same grouping and are the standard.

To fix, move the members to a module file and export them.

Reported
namespace N.M {}
declare module "x" {}
declare global {}
declare namespace Q {}
...
function local(require: (id: string) => void) { require("d"); }
...
js:
lint:
rules:
no-namespace: warn # off (default), warn, error

Enabled by the presets: js/typescript-eslint-recommended.

Suppress one line with sudsy-disable-next-line no-namespace in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
typescript-eslint no-namespace partial the option allowDeclarations keeps its default