I have one based enum like BasedColor
that I would like to use on other enum as AnotherState. If there is anyway to override the value with the same key. so I do not need to duplicate the key code . I guess I can create a new enum and duplicated the key abd assign to another value. but I am wondering if there is a better way to do it in typescript
enum BasedColor
{
First= 'red',
Second = 'blue'
}
enum AnotherState
{
First= 'light red',
Second = 'light blue'
Third = 'from another state third keu'
}
enums in TS are just objects. So, you can assign them to interfaces that they conform to, and you can "extend" one using the spread operator
...
.Now we can see how extending works:
This way you get inherited values but never have to rewrite the underlying enum, which can lead to unexpected behavior since enums are supposed to be constant after definition.