Skip to content

namespaceDeclarations

Reports using legacy namespace declarations.

✅ This rule is included in the ts logical preset.

Namespaces are a legacy feature of TypeScript that can lead to confusion and are not compatible with ECMAScript modules. Modern codebases generally use export and import statements to define and use ECMAScript modules instead.

namespace Values {
export const value = 123;
}
namespace Fruits {
export const apple = "🍎";
}

Whether to allow namespaces declared with the declare keyword.

ts.rules({
namespaceDeclarations: {
allowDeclarations: true,
},
});
namespace Values {
export const value = 123;
}
ts.rules({
namespaceDeclarations: {
allowDefinitionFiles: true,
},
});

Whether to allow namespaces in .d.ts and other definition files.

index.ts
declare namespace Values {
const value: number;
}

If your project uses TypeScript’s CommonJS export syntax (export = ...), you may need to use namespaces in order to export types from your module. You can learn more about this at:

If your project uses this syntax, either because it was architected before modern modules and namespaces, or because a module option such as verbatimModuleSyntax requires it, it may be difficult to migrate off of namespaces. In that case you may not be able to use this rule for parts of your project.

You might consider using Flint disable comments and/or configuration file disables for those specific situations instead of completely disabling this rule.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.