Effect CommunityEC
Effect Community3y ago
5 replies
Stephen Bluck

Using Default/Fallback in a Schema for Unknown Strings

Is there a way to use a default or fallback in a schema IF the schema fails?
const DeckType = S.union(
  S.literal('orange'),
  S.literal('red'),
  S.literal('green'),
  S.literal('purple'),
  S.literal('blue')
);

I want this as my schema but if an unknown string comes through, I want to default it to one the the defined literals.
Was this page helpful?