Effect CommunityEC
Effect Community2y ago
12 replies
mkrause

Extracting Schema Instance from Property Signature

Is there any way to get a Schema instance from a property signature? For example:

import { Schema as S } from '@effect/schema';

const Person = S.Struct({
  name: S.String,
  role: S.optional(S.Literal('a', 'b')),
});

const Role = Person.fields.role;

console.log(S.decodeSync(Role)('a')); // Error


What I'd like to do is to get access to the S.Literal('a', 'b') within the S.optional. Obviously it would be better here if the inner expression was factored out to its own schema to begin with, but a lot of times when working with existing schema definitions that's not feasible.
Was this page helpful?