Typescript is basically just a compile time type checking built on top of Javascript. Typescript enum types are just map (object) under the hood, you can have a look at this answer
Therefore, implement a toString
function to an enum type is quite straight forward. You can do it after defining the enum type. Just make sure that you don't put your implementation on .d.ts
files because these won't be compile into javascript code.
According the the answer link above, your enum type would be compiled into:
var VideoCategoryEnum;
(function (VideoCategoryEnum) {
VideoCategoryEnum[VideoCategoryEnum["knowledge"] = 0] = "knowledge";
VideoCategoryEnum[VideoCategoryEnum["condition"] = 1] = "condition";
// ...
})(VideoCategoryEnum || (VideoCategoryEnum = {}));
;
/* would equivalent to the following:
VideoCategoryEnum = {
"knowledge": 0,
"condition": 1,
...
"0": "knowledge",
"1": "condition",
}
*/
// since it's just basically an object, you can do whatever you want with it like below
// your implementation of toString
VideoCategoryEnum.toString = function() { return 'VideoCategoryEnum'; };