import * as Schema from "@effect/schema/Schema";
const MySchema = Schema.union(
Schema.struct({
type: Schema.struct({
name: Schema.literal("First"),
thingOne: Schema.number,
}),
}),
Schema.struct({
type: Schema.struct({
name: Schema.literal("Second"),
thingTwo: Schema.string,
}),
}),
);
Schema.parseSync(MySchema)({ type: { name: "First", thingThree: 2 } })
/*
Uncaught Error: error(s) found
├─ union member
│ └─ ["type"]["thingOne"]
│ └─ is missing
└─ union member
└─ ["type"]["name"]
└─ Expected "Second", actual "First"
*/
Schema.parseSync(MySchema)({ type: { name: "Second", thingThree: 2 } })
/*
Uncaught Error: error(s) found
├─ union member
│ └─ ["type"]["name"]
│ └─ Expected "First", actual "Second"
└─ union member
└─ ["type"]["thingTwo"]
└─ is missing
*/
import * as Schema from "@effect/schema/Schema";
const MySchema = Schema.union(
Schema.struct({
type: Schema.struct({
name: Schema.literal("First"),
thingOne: Schema.number,
}),
}),
Schema.struct({
type: Schema.struct({
name: Schema.literal("Second"),
thingTwo: Schema.string,
}),
}),
);
Schema.parseSync(MySchema)({ type: { name: "First", thingThree: 2 } })
/*
Uncaught Error: error(s) found
├─ union member
│ └─ ["type"]["thingOne"]
│ └─ is missing
└─ union member
└─ ["type"]["name"]
└─ Expected "Second", actual "First"
*/
Schema.parseSync(MySchema)({ type: { name: "Second", thingThree: 2 } })
/*
Uncaught Error: error(s) found
├─ union member
│ └─ ["type"]["name"]
│ └─ Expected "First", actual "Second"
└─ union member
└─ ["type"]["thingTwo"]
└─ is missing
*/