Effect CommunityEC
Effect Community•15mo ago
Kofi

Creating a Schema with Specific Literals and a Generic String Fallback

In typescript you can "bend" matching on strings a bit by defining a type like
type GenericOrSpecificString = "hello" | "hola" | "ciao" | (string & {});

This gives you the abilty of matching on some literals but also support a generic string type.

Is there a way of doing the same with schema? Schema.Union(Schema.String, Schema.Literal(...) only results in a string type.
https://effect.website/play#c0db2cf5484d

I guess another way of phrasing the problem would be: How can I decode for specific literals but fallback to a generic string if none of the literals are matched? ...while still being able to match on those literals 👀
Was this page helpful?