3 ms·
The comment below the one you linked is why namespaces remain useful: https://www.typescriptlang.org/docs/handbook/declaration-merging.html#merging-namespaces-
by duped 3y ago
The comment below the one you linked is why namespaces remain useful:
https://www.typescriptlang.org/docs/handbook/declaration-merging.html#merging-namespaces-with-classes-functions-and-enums https://www.typescriptlang.org/docs/handbook/declaration-mer...
It's a stretch to say "they're not needed." Like the comments in the threads you linked, they are usually not necessary for code written with esm modules in mind. However, modules cannot express the same semantics that namespaces can, and if you need those semantics for your program, you need namespaces.
Similarly, enums are not semantically equivalent to object literals with const fields, and I think it's kind of absurd to say that one of the most useful things in the TS type system is "not needed.
- nosianu 3y agoYES! I use that myself! It's the only way to extend an existing type from different modules. Use an interface and make use of the automatic declaration merging, and for that to be triggered it needs to be in the same namespace. Which since modules are each their own namespace needs the "namespace" declaration. But that is for TYPES and does not produce any JS code! > Similarly, enums are not semantically equivalent to object literals with const fields I know and I mentioned it! That still does not make them needed! You can use them if you want. As I mentioned. > I think it's kind of absurd to say that one of the most useful things in the TS type system is "not needed. I on the other hand think it's absurd to pretend to have a serious discussion when you claim that enums are "one of the most useful things" in TS. Some very minor syntactic sugar add-on as one of the main points of type checks???