I see two options here:
- Explicitly export the nested namespace
- Extract the nested namespace
Option 1
When working with namespaces, you can use the import keyword to create aliases, see https://www.typescriptlang.org/docs/handbook/namespaces.html#aliases. In my experience, this is one of the places where you can easily confuse (even experienced) developers, because the import keyword in this context is basically the equivalent of the var keyword - it has nothing to do with importing from modules or the like.
In your case, you can use it like so:
export namespace HTML_Validator { export namespace Localization { export type FileIsEmptyWarningLog = Readonly<Pick<WarningLog, "title" | "description">>; export namespace FileIsEmptyWarningLog { export type NamedParameters = Readonly<{ targetFileRelativePath: string; }>; } } } export import Localization = HTML_Validator.Localization;
Now, it is possible to import the Localization namespace in other places using import { Localization } from './my-html-validator';
Option 2
You could also explicitly extract the nested namespace, i.e. you could create a separate namespace like HTML_Validator_Localization, and reference it inside your HTML_Validator namespace. Then, similar to Option 1, you can import HTML_Validator_Localization using a named import from any other file.
export namespace HTML_Validator { export import Localization = HTML_Validator_Localization; } export namespace HTML_Validator_Localization { export type FileIsEmptyWarningLog = Readonly<Pick<WarningLog, "title" | "description">>; export namespace FileIsEmptyWarningLog { export type NamedParameters = Readonly<{ targetFileRelativePath: string; }>; } }
Again, we are using the import keyword here to declare the alias.
Note
If you are using eslint, you might run into issues with the no-unused-vars rule. See https://github.com/typescript-eslint/typescript-eslint/issues/4129