Typescript enhances Javascript by providing compile-time type checking. Enum types in Typescript are essentially mapped as objects, as explained in this helpful answer.
Adding a toString
function to an enum type is a simple task. Just remember not to include the implementation in .d.ts
files, as they will not be compiled into JavaScript.
Referring to the aforementioned answer link, your enum type would be transformed into:
var VideoCategoryEnum;
(function (VideoCategoryEnum) {
VideoCategoryEnum[VideoCategoryEnum["knowledge"] = 0] = "knowledge";
VideoCategoryEnum[VideoCategoryEnum["condition"] = 1] = "condition";
// ...
})(VideoCategoryEnum || (VideoCategoryEnum = {}));
;
/* which would be equivalent to:
VideoCategoryEnum = {
"knowledge": 0,
"condition": 1,
...
"0": "knowledge",
"1": "condition",
}
*/
// as it's essentially an object, you can customize it as needed
// implement your own toString function here
VideoCategoryEnum.toString = function() { return 'VideoCategoryEnum'; };