问题:
What is the difference in Typescript between export
and default export
.在 Typescript 中export
和default export
什么区别。 In all the tutorials I see people export
ing their classes and I cannot compile my code if I don't add the default
keyword before exporting.在所有教程中,我看到人们export
他们的类,如果我在导出之前不添加default
关键字,我将无法编译我的代码。
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.
错误是: error TS1192: Module '"src/app/MyClass"' has no default export.
解决方案:
参考一: https://stackoom.com/question/2FkOo参考二: Typescript export vs. default export