I tried to compile the following code in TypeScript to JavaScript:
namespace MyNamespace {
class MyClass {
public test() {
return 1;
}
}
}
If I replace the keyword namespace with module, it still generates exactly the same JavaScript code. So what is the difference between a module and namespace and when should I choose one over another?
So what is the difference between a module and namespace and when should I choose one over another
They are both exactly the same. module causes confusion with Native JavaScript (e.g ES6 module) so they decided to rename it to namespace.
In new code prefer to use namespace.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With