Effect CommunityEC
Effect Communityβ€’3y agoβ€’
29 replies
hipnotic3141

Issues with creating a schema with an opaque type

I am following the effect schema documentation regarding Extracting Inferred Types, and more specifically, the part about creating a schema with an opaque type. The sample in the documentation works (once you fix the typos), but then I changed the age to be an Option, and it stopped working.
import * as S from "@effect/schema/Schema";

const _Person = S.struct({
  name: S.string,
  age: S.option(S.number),
});

interface Person extends S.Schema.To<typeof _Person> {}

// Re-declare the schema to create a schema with an opaque type
const Person: Schema.Schema<Person> = _Person;

It's giving me this error
Type 'Schema<{ readonly name: string; readonly age: { readonly _tag: "None"; } | { readonly _tag: "Some"; readonly value: number; }; }, { readonly name: string; readonly age: Option<number>; }>' is not assignable to type 'Schema<Person, Person>'.
  The types returned by '[TypeId].From(...)' are incompatible between these types.
    Type '{ readonly name: string; readonly age: { readonly _tag: "None"; } | { readonly _tag: "Some"; readonly value: number; }; }' is not assignable to type 'Person'.ts(2322)
Was this page helpful?