Skip to content

Uncaught Error: A discriminator value for key could not be extracted from all schema options #2747

Discussion options

You must be logged in to vote
  1. z.discriminatedUnion requires the use of a z.literal or z.enum. It doesn't work with z.number.
  2. z.union([z.number(), z.null()]).nullish() is the same as z.number().nullish()

Try doing something like this:

const portfolioManagedInternalizationData = z.object( {
    serviceTypeId: z.literal( 'foo' )
} ).passthrough()

const portfolioAdviceInternalizationData = z.object( {
    serviceTypeId: z.enum( [ 'bar', 'baz' ] ),
    adviceTypeId: z.number().int(),
    bankingEntityId: z.number().nullish(),
} ).passthrough()

const portfolioInternalizationData = z.discriminatedUnion( 'serviceTypeId', [
    portfolioManagedInternalizationData,
    portfolioAdviceInternalizationData,
] )

console.log(
    

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@arthurvanl
Comment options

Answer selected by JacobWeisenburger
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