tag backbone attribute javascript typescript ava

javascript - backbone - Error:*.default no es un constructor



title label html (3)

Recibo el siguiente error, al probar un código javascript, transpilado desde un archivo de escritura de tipo.

Aquí está el error:

Error: _mapAction2.default is not a constructor

Aquí está la línea de código que causó el error:

var mapAction = new MapAction(MapActionType.POLYGONDRAGGED, []);

Aquí está el archivo mecanografiado original 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; } }

Aquí está el archivo .js transpilado 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


Compruebe que su importación es correcta. podrías perder {} por ejemplo.

import LatLngLiteral from '''';

a

import { LatLngLiteral } from '''';


Dado que las clases en javascript son azúcar sintáctica , pensé que intentaría resolver este problema sin ellas. Para mí, cambiar la arquitectura a prototipos parece haber resuelto mi problema. Publicación en caso de que alguien más se encuentre con este problema pero ya esté realizando la export default


Debe exportar un valor predeterminado que se verá así:

export default class MapAction implements IMapAction {...

Y lo importamos 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'';