I have an Enum in Java set up like so:
public enum ObjectType implements Serializable{
TABLE(0,"TABLE"),
VIEW(1,"VIEW");
private int objectType;
private String description;
private String sqlType;
ObjectType(int objectType, String description, String sqlType) {
this.objectType = objectType;
this.description = description;
this.sqlType = sqlType;
}
}
and I want to set up an equivalent Typescript Enum and I've done so like this:
export enum ObjectType {
TABLE,
VIEW
}
export namespace ObjectType {
export function getType(description : string): ObjectType {
if(description.toUpperCase() === "TABLE") {
return ObjectType.TABLE;
} else if(description.toUpperCase() === "VIEW") {
return ObjectType.VIEW;
} else {
return null;
}
}
export function getObjectType(objectType: ObjectType): string {
switch(objectType) {
case ObjectType.TABLE:
return "TABLE";
case ObjectType.VIEW:
return "VIEW";
}
}
}
My question is, can I create a constructor function which has a description and sqlType in Typescript as well?