Effect CommunityEC
Effect Community3y ago
38 replies
Stephen Bluck

Composing Schemas and Overwriting Error Messages

How can I compose schemas together and overwrite their error messages? Take this as an example:

export const NonEmptyString50 = String.pipe(S.nonEmpty(), S.maxLength(50));

export const Title = NonEmptyString50.pipe(
  S.message(() => "The title is required"),
  S.brand("Title")
);

// Expected a non empty string, actual ""
S.parseSync(Title)("");

I have defined a NonEmptyString50 which I would like to compose with other schemas however I don't want to define error messages at the NonEmptyString50 level because it doesn't have enough context. I would like to define the error messages at the highest level if possible, does anyone know if it is possible?
Was this page helpful?