問題:
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