Suppose I have two enums as described below in Typescript, then How do I merge them
enum Mammals {
Humans,
Bats,
Dolphins
}
enum Reptiles {
I'm not going to propose a solution to merge to enums (I couldn't find a proper way to do it)
But if you want something behaving like an enum from the way you consume it, you could still use merged object in javascript.
enum Mammals {
Humans = 'Humans',
Bats = 'Bats',
Dolphins = 'Dolphins',
}
enum Reptiles {
Snakes = 'Snakes',
Alligators = 'Alligators',
Lizards = 'Lizards',
}
const Animals = {
...Mammals,
...Reptiles,
}
type Animals = Mammals | Reptiles
Then you could use Animals.Snakes or Animals.Dolphins and both should be properly typed and work as an enum