Can you tell if it possible to create enum like this in Typescript?
public enum FooEnum {
ITEM_A(1), ITEM_B(2), ITEM_C(3);
private int order;
private FooEnum (int order) {
this.order = order;
}
public int getOrder() {
return order;
}
}
I have enum like this:
export enum FooEnum {
ITEM_A = 'ITEM_A',
ITEM_B = 'ITEM_B',
ITEM_C = 'ITEM_C',
}
which I am using in TypeORM entities
@Column({ type: 'enum', enum: FooEnum })
foo!: FooEnum
I need to assign enum values to numbers to define their priority. Is possible to do that?
I had also idea to create value object with constants like you can see below but I don't know to use this class on entity, to still save Foo.ITEM_A like 'ITEM_A' string
class Foo {
public static ITEM_A = new Country(1);
public static ITEM_B = new Country(2);
public static ITEM_C = new Country(3);
constructor(order: number) {
this.order = order;
}
readonly order: number;
}