I am creating an application by TypeScript and using WebPack to transpile and bundle. I am using the final result of this application in a pure JavaScript website. In this application I have defined an enum as below:
export const enum ShapeType {
Actor,Ellipse,Border,Connector
}
I also exported it as:
export { ShapeType } from "./shape/shape.type";
But when I try to use it like:
var createdShape = new shapeFactory.createShape(ShapeType.Ellipse);
It does not create a shape and when I debug I see this error:"ShapeType is not defined" I also try to find ShapeType in the final JavaScript bundle file, but I found out there is no ShapeType in the bundle file too. I don't have a problem when I import it inside TS.
The code below is the js code. ChartDraw is the library name I defined in my webpack config file. All other functions work fine. The only problem is with
var aa = shapeFactory.createShape(ChartDraw.ShapeType.Ellipse);
because ShapeType is not defined.
var svg = new ChartDraw.Svg("drawing");
var shapeFactory = new ChartDraw.ShapeFactory(svg);
var ob1 = null;
var ob2 = null;
//aa.draw();
var cc = new ChartDraw.Connector(svg);
var bb = new ChartDraw.MouseReader();
bb.setExportFunction(info => {
var aa = shapeFactory.createShape(ChartDraw.ShapeType.Ellipse);
aa.rectangularPosition = info;
aa.draw();
if (ob1 == null)
ob1 = aa;
else {
ob2 = info;
cc.beginObject = ob1;
cc.endObject = aa;
cc.draw();
}
});
And the code below is where I import ShapeType:
import { ShapeType } from "./shape.type";
import { Actor } from "./actor";
import { Svg } from "../svg";
import { Shape } from "./shape";
import { Ellipse } from "./ellipse";
export class ShapeFactory {
private svg: Svg;
constructor(svg: Svg) {
this.svg = svg;
}
public createShape(shape: ShapeType):Shape {
switch (shape) {
case ShapeType.Actor:
let actor = new Actor(this.svg);
return actor;
case ShapeType.Ellipse:
let ell = new Ellipse(this.svg);
return ell;
}
}
}