For my TypeScript application, I am utilizing WebPack to transpile and bundle the code. The final result is intended to be used in a pure JavaScript website. One of the components in my application is an enum defined as follows:
export const enum ShapeType {
Actor, Ellipse, Border, Connector
}
I have also exported it as:
export { ShapeType } from "./shape/shape.type";
However, when I attempt to use it like this:
var createdShape = new shapeFactory.createShape(ShapeType.Ellipse);
I encounter an error stating: "ShapeType is not defined". Despite my efforts to locate ShapeType in the final JavaScript bundle file, it seems to be missing from there as well. Interestingly, I do not face any issues when importing it within TypeScript.
The following snippet of code represents the JavaScript code. The library name is ChartDraw, as specified in my webpack configuration file. All functions except for the one involving
var aa = shapeFactory.createShape(ChartDraw.ShapeType.Ellipse);
are working efficiently. The problem arises as ShapeType is not recognized.
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();
}
});
The code snippet below illustrates where ShapeType is imported:
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;
}
}
}