This page is not yet available in Spanish. We are working on its translation.
If you have any questions or feedback about our current translation project, feel free to reach out to us!

Metadata

ID: typescript-best-practices/no-namespace

Language: TypeScript

Severity: Notice

Category: Best Practices

Description

Namespaces should be avoided as an outdated feature of TypeScript. Use module syntax instead.

Non-Compliant Code Examples

module foo {}
namespace foo {}
module foo {}
namespace foo {}
module foo {}
namespace foo {}
declare module foo {}
declare namespace foo {}
declare module foo {}
declare namespace foo {}
namespace foo {}
module foo {}
declare module foo {}
declare namespace foo {}
namespace Foo.Bar {}
namespace Foo.Bar { namespace Baz.Bas { interface X {} } }
namespace A { namespace B { declare namespace C {} }
namespace A { namespace B { export declare namespace C {} } }
namespace A { declare namespace B { namespace C {} } }
namespace A { export declare namespace B { namespace C {} } }
namespace A { export declare namespace B { declare namespace C {} } }
namespace A { export declare namespace B { export declare namespace C {} } }
namespace A { declare namespace B { export declare namespace C {} } }
namespace A { export namespace B { export declare namespace C {} } }
export namespace A { namespace B { declare namespace C {} } }
export namespace A { namespace B { export declare namespace C {} } }
export namespace A { declare namespace B { namespace C {} } }
export namespace A { export declare namespace B { namespace C {} } }
export namespace A { export declare namespace B { declare namespace C {} } }
export namespace A { export declare namespace B { export declare namespace C {} } }
export namespace A { declare namespace B { export declare namespace C {} } }
export namespace A { export namespace B { export declare namespace C {} } }

Compliant Code Examples

declare global {}
declare module 'foo' {}
declare module foo {}
declare namespace foo {}
declare global { namespace foo {} }
declare module foo { namespace bar {} }
declare global { namespace foo { namespace bar {} } }
declare namespace foo { namespace bar { namespace baz {} } }
export declare namespace foo { export namespace bar { namespace baz {} } }
namespace foo {}
module foo {}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis