Effect CommunityEC
Effect Community2y ago
69 replies
Aldwin

Accessing Enum Values in TypeScript for Reuse

How can I access an Enum's values? I'd like to do something like this:

const TrafficLightState = S.enums({
  Red: 0,
  Yellow: 1,
  Green: 2,
} as const);

const PedestrianLightState = S.enums({
  Red: TrafficLightState.values.Red, //<- but there's no `values` prop
  Green: TrafficLightState.values.Green,
} as const);


I'm open to alternative ways of doing this, too!
Was this page helpful?