我已经了解了如何加载模块(提示:在相对引用文件时,即使是在同一个文件夹中),应该始终从./开始,并创建了一个完全使用TypeScript编写的应用程序。
我目前面临的问题是:如何使用我编写的模块?现在我正在使用一个类似于以下内容的main.js文件:
require(['my/typescript/module'], function(module) {
//my application boostrapping code goes here
});但通过这样做,我失去了TypeScript的各种优势:
import {Module} from './my/typescript/module'在我看来要干净得多)因此,我想知道是否有可能将ES6导入和TypeScript组合起来,生成一个require()-enclosed JS文件而不是一个define() JS文件。
发布于 2016-05-20 19:11:58
要使用es6样式的导入,我认为您应该先导出模块。
export default class SomeRamdomClass {
hello(name: string) {
return `hello ${name}`;
}
}
import importedRamdomClass from "./SomeRamdomClass";
let greeting = new importedRamdomClass();
console.log(greeting.hello('Jon'));
更多信息可以在TypeScriptLang上找到。
https://stackoverflow.com/questions/37352821
复制相似问题