Typescript export vs. default export

What is the difference in Typescript between export and default export. In all the tutorials I see people exporting their classes and I cannot compile my code if I don’t add the default keyword before exporting.

Also, I couldn’t find any trace of the default export keyword in the official typescript documentation.

export class MyClass {

  collection = [1,2,3];

}

Does not compile. But:

export default class MyClass {

  collection = [1,2,3];

}

Does.

The error is: error TS1192: Module '"src/app/MyClass"' has no default export.

4 Answers
4

Leave a Comment