Effect CommunityEC
Effect Community2y ago
36 replies
Aldwin

Equivalent of io-ts Enum Annotations in Schema?

Coming from io-ts, I kind of miss the Enum annotations. I used to do the below kind of thing a lot. Is there an equivalent in Schema?

type TrafflicLight = io.TypeOf<typeof TrafficLight>;
const TrafflicLight = io.enums({
  Red: {canDrive: false, shouldDrive: false},
  Yellow: {canDrive: true, shouldDrive: false},
  Green: {canDrive: true, shouldDrive: true},
});

const canDrive = (light: TrafflicLight) => TrafflicLight.enums[light].canDrive;
const shouldDrive = (light: TrafflicLight) => TrafflicLight.enums[light].shouldDrive;
Was this page helpful?