Effect CommunityEC
Effect Community2y ago
8 replies
Zaymon

Issue with optional strings in schema validation

const Email = S.string.pipe(
  S.pattern(/^(?!\.)(?!.*\.\.)([A-Z0-9_+-.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9-]*\.)+[A-Z]{2,}$/i),
);

// -- Types and validation.
const FeedbackFormSchema = S.struct({
  name: S.optional(S.string.pipe(S.nonEmpty(), S.maxLength(120))),
  email: S.optional(Email.pipe(S.nonEmpty(), S.maxLength(256))),
  message: S.optional(S.string.pipe(S.nonEmpty(), S.maxLength(10000))),
});


I've got this schema. I'm getting a frustrating error on my optional strings: "expected undefined but got """ (or any other string value). Any tips?
Was this page helpful?