Effect CommunityEC
Effect Community2y ago
13 replies
Stephen Bluck

Troubleshooting TS Error with Composed Schemas in TypeScript

Is there a way I can compose these schemas? The branded type is causing a TS error:
const OptionFromEmptyString: S.Schema<Option.Option<string>, string> = S.transform(
  S.string,
  S.option(S.string),
  (a) => (a.length > 0 ? Option.some(a) : Option.none()),
  (a) => (a._tag === "Some" ? a.value : ""),
);

const FirstName = S.string.pipe(S.brand("Name"));

const MaybeFirstName = S.compose(OptionFromEmptyString, FirstName);
Was this page helpful?