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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章