Skip to content

[BUG] namespace XXX {} is a slow and out-of-date syntax that typescript team itself moved away from #408

@loynoir

Description

@loynoir

Description

evanw/esbuild#3077 (comment)

Evanw suggest syntax of import * as TypeRegistry from './lib.mjs'.

Which have is a dot property syntax, like namespace, with tree shake support.

evanw/esbuild#3077 (comment)

It's the opinion of the TypeScript team that if you are already using ESM syntax, then you should probably shouldn't be using TypeScript namespaces for code organization

The TypeScript code base itself even moved away from TypeScript namespaces to ES modules because ES modules are better.

microsoft/TypeScript#30994 (comment)

Namespaces are probably never going away and, simultaneously, you probably shouldn't use them, since better, more standard and modern patterns exist through the use of modules. If you have code that you feel needs to use a namespace, more power to you and go for it, but most of the time you don't need one, as we now have a different conceptual organizational model recommended for large-scale JS (modules).

most new TS code should probably never need to use them, and should think hard about if they really need to.

Minimally, we'll never outright remove namespaces because they're incredibly useful for describing type hierarchies and the like of existing cjs libraries - it's just that modern esm-like code probably doesn't need them, since the module itself is a namespace (where nesting is achieved thru reexports).

microsoft/TypeScript#39247

microsoft/TypeScript#51387

The TypeScript compiler is now implemented internally with modules, not namespaces. The compiler is now 10-25% faster. tsc is now 30% faster to start. Our npm package is now 43% smaller. More improvements are in the works.

Related

#401

#399

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions