Recibo el siguiente error, cuando pruebo un código javascript, transpilado de un archivo mecanografiado.
Aquí está el error:
Error: _mapAction2.default is not a constructorAquí está la línea de código que causó el error:
var mapAction = new MapAction(MapActionType.POLYGONDRAGGED, []);Aquí está el map-action.ts del archivo mecanografiado original:
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; } }Aquí está el archivo .js map-action.js transpilado :
"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.mapDebe exportar un valor predeterminado que se verá así:
export default class MapAction implements IMapAction {...E importarlo como:
import MapAction from './map_action_file';Alternativamente, si desea exportar varias cosas desde el módulo, puede hacer algo como:
export class MapAction ... export class MapSomethng ...E importarlo de la siguiente manera:
import { MapAction, MapSomething } from './map_action_file';Otra solución sería agregar "esModuleInterop": true, en tsconfig.json .
esModuleInterop permite importaciones predeterminadas desde módulos sin exportación predeterminada.
Comprueba que tu importación es correcta. es posible que te pierdas {} por ejemplo.
import LatLngLiteral from '';para
import { LatLngLiteral } from '';