export和default export在打字方面有什么不同?在所有的教程中,我看到人们在export他们的类,如果我在导出之前不添加default关键字,我就不能编译我的代码。
此外,我在官方typescript documentation中找不到默认导出关键字的任何踪迹。
export class MyClass {
collection = [1,2,3];
}不编译。但是:
export default class MyClass {
collection = [1,2,3];
}确实如此。
错误是:error TS1192: Module '"src/app/MyClass"' has no default export.
发布于 2017-12-14 20:47:26
下面是简单对象导出的示例。
var MyScreen = {
/* ... */
width : function (percent){
return window.innerWidth / 100 * percent
}
height : function (percent){
return window.innerHeight / 100 * percent
}
};
export default MyScreen在主文件中(当你不想和不需要创建新实例时使用),并且它不是全局的,你将只在需要的时候导入它:
import MyScreen from "./module/screen";
console.log( MyScreen.width(100) );https://stackoverflow.com/questions/33305954
复制相似问题