-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discriminated union doesn't work with transform
#1171
Comments
Same issue here, love this operator, but I need to rename keys before the discriminatedUnion |
Does anyone know any workaround? This makes adding certain optional types based on other fields impossible, forcing you to always provide those |
I made a pull request to address this issue as I have the same problem. Waiting for merge or feedback |
I'm hitting this too, would love to see @roblabat's PR make it through |
I'm also hitting this. |
…natedUnion (#1290) * #1171 * fix tests * add superRefine in tests * add support for lazy * fix typings * fixe typings for asserted lazy * fix * clean console.log from debug * Clean up discriminatedUnion * Fix deno test Co-authored-by: Colin McDonnell <[email protected]>
I see the fix is now available in v3.20.0-beta, but when I upgraded and tried the first example I got this error:
Am I doing something wrong? |
same here, using the newest version (3.21.4) export const BaseRegistryTag = z
.object({
id: z.optional(z.string()),
name: z.string(),
description: z.optional(z.string()),
})
.strict();
const positiveNumber = z.number().positive().finite()
const hasLengthType = z.object({
minLength: positiveNumber,
maxLength: positiveNumber
}).refine((data) => data.maxLength >= data.minLength, "maxLength should be greater than or equal to minLength.")
export const NumberTag = BaseRegistryTag.extend({
type: z.literal('number'),
precision: z.optional(positiveNumber),
}).and(hasLengthType)
export const TextTag = BaseRegistryTag.extend({
type: z.literal('text'),
}).and(hasLengthType)
export const RegistryTag = z.discriminatedUnion('type', [NumberTag, TextTag]) gives:
|
Possibly it is not bug. Any way to "post"-define discriminator (define in
transform
)?Codesandbox example 1
Codesandbox example 2
Example 1:
Example 2:
Error: The discriminator value could not be extracted from all the provided schemas
The text was updated successfully, but these errors were encountered: