namespaceDeclarations
Reports using legacy
namespacedeclarations.
✅ This rule is included in the tslogicalandlogicalStrictpresets.
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.
Examples
Section titled “Examples”namespace namespace Values
Values { export const const Values.value: 123
value = 123;}namespace namespace Fruits
Fruits { export const const Fruits.apple: "🍎"
apple = "🍎";}export const const value: 123
value = 123;export const const Fruits: { apple: string;}
Fruits = { apple: string
apple: "🍎",};Options
Section titled “Options”allowDeclarations
Section titled “allowDeclarations”Whether to allow namespaces declared with the declare keyword.
const ts: Plugin<RuleAbout, "all" | "javascript" | "typescript", [Rule<{ readonly description: "Reports getter and setter accessors for the same property that are not adjacent."; readonly id: "accessorPairGroups"; readonly presets: ["stylistic", "stylisticStrict"];} & { presets?: ("javascript" | "logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[]; url: string;}, object, object, "notGrouped", AnyOptionalSchema>, Rule<{ readonly description: "Reports mismatched types between getter and setter accessor pairs."; readonly id: "accessorPairTypes"; readonly presets: [...];} & { presets?: ("javascript" | "logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[]; url: string;}, object, object, "mismatchedTypes", AnyOptionalSchema>, ... 290 more ..., Rule<...>]>
ts.Plugin<RuleAbout, "all" | "javascript" | "typescript", [Rule<{ readonly description: "Reports getter and setter accessors for the same property that are not adjacent."; readonly id: "accessorPairGroups"; readonly presets: [...]; } & { ...; }, object, object, "notGrouped", AnyOptionalSchema>, ... 291 more ..., Rule<...>]>.rules: (rulesOptions: PluginRulesOptions<[Rule<{ readonly description: "Reports getter and setter accessors for the same property that are not adjacent."; readonly id: "accessorPairGroups"; readonly presets: ["stylistic", "stylisticStrict"];} & { presets?: ("javascript" | "logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[]; url: string;}, object, object, "notGrouped", AnyOptionalSchema>, Rule<{ readonly description: "Reports mismatched types between getter and setter accessor pairs."; readonly id: "accessorPairTypes"; readonly presets: [...];} & { presets?: ("javascript" | "logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[]; url: string;}, object, object, "mismatchedTypes", AnyOptionalSchema>, ... 290 more ..., Rule<...>]>) => [...]
Defines rules to configure or disable on files in a config.
rules({ namespaceDeclarations?: boolean | { allowDeclarations?: boolean | undefined; allowDefinitionFiles?: boolean | undefined;} | undefined
namespaceDeclarations: { allowDeclarations?: boolean | undefined
allowDeclarations: true, },});namespace namespace Values
Values { export const const Values.value: 123
value = 123;}declare namespace namespace Values
Values { const const Values.value: number
value: number;}allowDefinitionFiles
Section titled “allowDefinitionFiles”const ts: Plugin<RuleAbout, "all" | "javascript" | "typescript", [Rule<{ readonly description: "Reports getter and setter accessors for the same property that are not adjacent."; readonly id: "accessorPairGroups"; readonly presets: ["stylistic", "stylisticStrict"];} & { presets?: ("javascript" | "logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[]; url: string;}, object, object, "notGrouped", AnyOptionalSchema>, Rule<{ readonly description: "Reports mismatched types between getter and setter accessor pairs."; readonly id: "accessorPairTypes"; readonly presets: [...];} & { presets?: ("javascript" | "logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[]; url: string;}, object, object, "mismatchedTypes", AnyOptionalSchema>, ... 290 more ..., Rule<...>]>
ts.Plugin<RuleAbout, "all" | "javascript" | "typescript", [Rule<{ readonly description: "Reports getter and setter accessors for the same property that are not adjacent."; readonly id: "accessorPairGroups"; readonly presets: [...]; } & { ...; }, object, object, "notGrouped", AnyOptionalSchema>, ... 291 more ..., Rule<...>]>.rules: (rulesOptions: PluginRulesOptions<[Rule<{ readonly description: "Reports getter and setter accessors for the same property that are not adjacent."; readonly id: "accessorPairGroups"; readonly presets: ["stylistic", "stylisticStrict"];} & { presets?: ("javascript" | "logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[]; url: string;}, object, object, "notGrouped", AnyOptionalSchema>, Rule<{ readonly description: "Reports mismatched types between getter and setter accessor pairs."; readonly id: "accessorPairTypes"; readonly presets: [...];} & { presets?: ("javascript" | "logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[]; url: string;}, object, object, "mismatchedTypes", AnyOptionalSchema>, ... 290 more ..., Rule<...>]>) => [...]
Defines rules to configure or disable on files in a config.
rules({ namespaceDeclarations?: boolean | { allowDeclarations?: boolean | undefined; allowDefinitionFiles?: boolean | undefined;} | undefined
namespaceDeclarations: { allowDefinitionFiles?: boolean | undefined
allowDefinitionFiles: true, },});Whether to allow namespaces in .d.ts and other definition files.
declare namespace namespace Values
Values { const const Values.value: number
value: number;}declare namespace namespace Values
Values { const const Values.value: number
value: number;}When Not To Use It
Section titled “When Not To Use It”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:
- TypeScript#52203, the pull request introducing
verbatimModuleSyntax - TypeScript#60852, an issue requesting syntax to export types from a CommonJS module.
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.
Further Reading
Section titled “Further Reading”- TypeScript handbook entry on Modules
- TypeScript handbook entry on Namespaces
- TypeScript handbook entry on Namespaces and Modules
Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noNamespace - Deno:
no-namespace - ESLint:
@typescript-eslint/no-namespace - Oxlint:
typescript/no-namespace