Skip to content

Discriminated union of another discriminated union #2180

Discussion options

You must be logged in to vote

Everything seems to be working fine when I use z.union. Seems like a problem with react-hook-form zod resolver.

const SolarEnergySchema = z.object( {
    type: z.literal( 'Solar' ),
    solarField1: z.string(),
    solarField2: z.string(),
    uploadCsv: z.literal( false )
} )

const WindEnergySchema = z.object( {
    type: z.literal( 'Wind' ),
    windField1: z.string(),
    windField2: z.string(),
    uploadCsv: z.literal( false )
} )

const WaterEnergySchema = z.object( {
    type: z.literal( 'Water' ),
    waterField1: z.string(),
    waterField2: z.string(),
    uploadCsv: z.literal( false )
} )

const EnergyUnionSchema = z.discriminatedUnion( 'type', [
    SolarEnergySchema,
    Win…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@jamesarosen
Comment options

Answer selected by JacobWeisenburger
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #2170 on March 10, 2023 13:03.