Effect CommunityEC
Effect Community2y ago
3 replies
Rory

Creating a Safe Discriminated Union in TypeScript Without Failing on Unimplemented Types

Checking if I'm missing something. Wanting a discriminated union over type, however I do not want to fail by encountering a type I did not implement yet. Is this the way to express?
const E = S.union(
  S.struct({type: S.literal('foo'), data: S.string}),
  S.struct({type: S.literal('bar'), data: S.number}),
  S.struct({type: S.string})
)
Was this page helpful?