export const typeASchema = z.object({ type: z.literal('A'), name: z.string(), }); export type TypeA = z.infer<typeof typeASchema>; export const typeBSchema = z.object({ type: z.literal('B'), count: z.number(), }); export type TypeB = z.infer<typeof typeBSchema>; export const typeCSchema = z.object({ type: z.literal('C'), value: z.string(), }); export type TypeC = z.infer<typeof typeCSchema>; // ↓この typesSchema はただの中間介在物でしかない、、 const typesSchema = z.union([typeASchema, typeBSchema, typeCSchema]); export type Types = z.infer<typeof typesSchema>;