-
Notifications
You must be signed in to change notification settings - Fork 194
Description
Description
Evanw suggest syntax of import * as TypeRegistry from './lib.mjs'.
Which have is a dot property syntax, like namespace, with tree shake support.
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).
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.