错误:* .default不是构造函数 [英] Error: *.default is not a constructor
本文介绍了错误:* .default不是构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在测试一些javascript代码时遇到以下错误,从一个打字稿文件中转换出来。
I get the following error, when testing some javascript code, transpiled from a typescript file.
这是错误:
Error: _mapAction2.default is not a constructor
以下是导致错误的代码行:
Here is the line of code that caused the error:
var mapAction = new MapAction(MapActionType.POLYGONDRAGGED, []);
这是原始的打字稿文件 map-action.ts :
Here is the original typescript-file map-action.ts:
import { IMapAction} from './imap-action';
import { MapActionType } from './map-action-type.enum';
import {LatLngLiteral} from 'angular2-google-maps/core';
export class MapAction implements IMapAction{
type: MapActionType;
paths: Array<LatLngLiteral>;
constructor(mapActionType: MapActionType, paths: Array<LatLngLiteral>){
this.type = mapActionType;
this.paths = paths;
}
public getType(): MapActionType{
return this.type;
}
public getPaths(): Array<LatLngLiteral>
{
return this.paths;
}
}
这是已编译的.js-文件 map-action.js :
Here is the transpiled .js-file map-action.js:
"use strict";
class MapAction {
constructor(mapActionType, paths) {
this.type = mapActionType;
this.paths = paths;
}
getType() {
return this.type;
}
getPaths() {
return this.paths;
}
}
exports.MapAction = MapAction;
//# sourceMappingURL=map-action.js.map
推荐答案
您需要导出默认值,如下所示:
You need to export a default value which will look like:
export default class MapAction implements IMapAction {...
并将其导入为:
import MapAction from './map_action_file';
或者,如果你想从模块中导出多个的东西,你可以做类似的事情:
Alternatively, if you want to export multiple things from the module you can do something like:
export class MapAction ...
export class MapSomethng ...
并按如下方式导入:
import { MapAction, MapSomething } from './map_action_file';
这篇关于错误:* .default不是构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文