Open guillaume-docquier-vention opened 3 months ago
type AgentBaseInput = z.input<typeof agentBaseSchema> & {
type: AgentType
}
type AgentBaseOutput = z.output<typeof agentBaseSchema> & {
type: AgentType
}
// ...
const agentSchema = z.union([codeFreeAgentSchema, machineCodeAgentSchema]) satisfies z.ZodSchema<AgentBaseOutput, any, AgentBaseInput>
I have a brand in a base schema, which I extend to add additional data, like so:
TS playground
The
agents
are consumed as a discriminated union on thetype
, as you can see. I'm doing thesatisfies
bit to ensure that new schemas are created properly by other people in the team.Is there a way to do this? Should I not be doing this?
It seems to be the same idea as https://github.com/colinhacks/zod/issues/2076, but I don't really understand how to apply the solution to my use case since I don't have input/output schemas.