3

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?

1

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.