这可能是我的误会。在 Typescript 1.4 中,我们用于导出导入类,但是当我将代码更新为 Typescript 1.5 时,行为发生了变化。
这是它在 TS 1.4 中的工作方式
LanguageForm.ts
import AbstractForm = require('../components/AbstractForm');
class LanguageForm extends AbstractForm {
buildPanel(){
}
}
export = LanguageForm;
根据我对 TS 1.5 的理解,语法需要修改为:
import AbstractForm from '../components/AbstractForm';
export default class LanguageForm extends AbstractForm {
buildPanel(){
}
}
在 TS1.4 中,我可以简单地调用 new
以使其在动态设置中工作:
require(["LanguageForm"], (Form) => {
new Form()
});
现在在 TS 1.5 中我需要做的:
require(["LanguageForm"], (Form) => {
new Form.default()
});
我的问题
在所有示例中,我发现文档正在导出/导入模块。那是导出/导入类的方式吗?我可以去掉 .default
吗?
最佳答案
In all the example I found the documentation was exporting/importing modules. Is that the way to export/import classes
不要使用export =
。而是导出:
export class LanguageForm extends AbstractForm {
buildPanel(){
}
}
并导入:
import {LanguageForm} from '../components/LanguageForm';
关于Typescript 1.5 导出/导入类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31679537/