I am looking for a way to statically set an enum on my TypeScript class and be able to reference it both internally and externally by exporting the class. As I am new to TypeScript, I am unsure of the correct syntax for this. Below is some pseudo-code (which extends a Backbone Model) that outlines what I am trying to achieve...
class UnitModel extends Backbone.Model {
static enum UNIT_STATUS {
NOT_STARTED,
STARTED,
COMPLETED
}
defaults(): UnitInterface {
return {
status: UNIT_STATUS.NOT_STARTED
};
}
isComplete(){
return this.get("status") === UNIT_STATUS.COMPLETED;
}
complete(){
this.set("status", UNIT_STATUS.COMPLETED);
}
}
export = UnitModel;
I want to access the enum inside this class as well as outside the class, such as shown below:
import UnitModel = require('path/to/UnitModel');
alert(UnitModel.UNIT_STATUS.NOT_START);//I expect to see 0 since enums start at 0