Typescript 导出与默认导出 - Typescript export vs. default export

问题:

What is the difference in Typescript between export and default export .在 Typescript 中exportdefault 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章