Effect Schema Type Parity
Instructions
- •Define the domain type first (prefer
interface), then define the schema and assert parity. - •Always use
satisfies Schema.Schema<YourType, any>on the schema. - •Add
assert<Equals<typeof YourSchema.Type, Readonly<YourType>>>()usingtsafe. - •If the
assert<Equals<...>>isn't typed correctly but thesatisfiesis, you can optionally add the_check1/_check2assignments withvoid(seeZerospinCommandSchema). - •When validating unknown input against an Effect schema, prefer
validateUnknownfromzerospinif available.
Example
ts
import type { Equals } from 'tsafe';
import { Schema } from 'effect';
import { assert } from 'tsafe';
export interface IFoo {
bar: string;
}
export const ZFoo = Schema.Struct({
bar: Schema.String,
}) satisfies Schema.Schema<IFoo, any>;
const _check1: typeof ZFoo.Type = {} as IFoo;
const _check2: IFoo = {} as typeof ZFoo.Type;
void _check1;
void _check2;
assert<Equals<typeof ZFoo.Type, Readonly<IFoo>>>();