Effect CommunityEC
Effect Community3y ago
21 replies
bsluther

Matching Discriminated Union with String Literal Schema

I'm trying to match over a discriminated union, where the discriminator is a string literal defined with Schema, but when the schema defines a union of literals (either via S.literal('first', 'second') or S.union(S.literal('first'), S.literal('second')), the type in the match becomes never. Example:

const Shirt = S.struct({
  _tag: S.literal('Red', 'Blue')
})
interface Shirt extends S.To<typeof Shirt> {}

pipe(
  Match.type<Shirt>(),
  Match.tag('Red', x => x)
)

Here x is of type never, unless I get rid of the second argument to S.literal.

Is this the expected behavior? Wondering if I have package version problem
Was this page helpful?