We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I am trying to create schema with conditional fields and I get:
[{ "resource": "/home/waszi/git/hosteam/htpanel-frontend/src/routes/(website)/product/[id]/ProductForm.svelte", "owner": "_generated_diagnostic_collection_name_#0", "code": "2769", "severity": 8, "message": "No overload matches this call.\n Overload 1 of 2, '(schema: ZodValidation<AnyZodObject>, options?: SuperValidateOptions | undefined): SuperValidated<AnyZodObject, any>', gave the following error.\n Argument of type '{ type: \"vps\" | \"hosting\" | \"dedicated\" | \"domain\"; description: string; product: string; cycle: string; }' is not assignable to parameter of type 'ZodValidation<AnyZodObject>'.\n Type '{ type: \"vps\" | \"hosting\" | \"dedicated\" | \"domain\"; description: string; product: string; cycle: string; }' is missing the following properties from type 'ZodEffects<ZodEffects<ZodEffects<ZodEffects<ZodEffects<AnyZodObject, { [x: string]: any; }, { [x: string]: any; }>, { [x: string]: any; }, { [x: string]: any; }>, { [x: string]: any; }, { ...; }>, { ...; }, { ...; }>, { ...; }, { ...; }>': innerType, sourceType, _parse, _type, and 32 more.\n Overload 2 of 2, '(data: FormData | URLSearchParams | URL | Partial<{ [x: string]: any; }> | null | undefined, schema: ZodValidation<AnyZodObject>, options?: SuperValidateOptions | undefined): SuperValidated<...>', gave the following error.\n Argument of type 'ZodIntersection<ZodUnion<[ZodObject<{ type: ZodLiteral<\"dedicated\">; os: ZodString; bandwidth: ZodString; antiddos: ZodString; }, \"strip\", ZodTypeAny, { ...; }, { ...; }>, ZodObject<...>, ZodObject<...>, ZodObject<...>]>, ZodObject<...>>' is not assignable to parameter of type 'ZodValidation<AnyZodObject>'.\n Type 'ZodIntersection<ZodUnion<[ZodObject<{ type: ZodLiteral<\"dedicated\">; os: ZodString; bandwidth: ZodString; antiddos: ZodString; }, \"strip\", ZodTypeAny, { ...; }, { ...; }>, ZodObject<...>, ZodObject<...>, ZodObject<...>]>, ZodObject<...>>' is missing the following properties from type 'ZodEffects<ZodEffects<ZodEffects<ZodEffects<ZodEffects<AnyZodObject, { [x: string]: any; }, { [x: string]: any; }>, { [x: string]: any; }, { [x: string]: any; }>, { [x: string]: any; }, { ...; }>, { ...; }, { ...; }>, { ...; }, { ...; }>': innerType, sourceType", "source": "ts", "startLineNumber": 40, "startColumn": 27, "endLineNumber": 40, "endColumn": 70 }]
Fragment of my code:
export const typeEnum = z.enum(['vps', 'hosting', 'dedicated', 'domain']); const _CartItemCommon = z.object({ cycle: z.string(), product: z.string(), description: z.string() }); const _CartItemDedicated = z.object({ type: z.literal(typeEnum.enum.dedicated), os: z.string(), bandwidth: z.string(), antiddos: z.string() }); const _CartItemDomain = z.object({ type: z.literal(typeEnum.enum.domain), tld: z.string(), domain: z.string() }); const _CartItemHosting = z.object({ type: z.literal(typeEnum.enum.hosting) }); const _CartItemVps = z.object({ type: z.literal(typeEnum.enum.vps), os: z.string() }); const _CartItemCond = z.discriminatedUnion("type", [ _CartItemDedicated, _CartItemDomain, _CartItemHosting, _CartItemVps ]); export const _CartItem = z.intersection(_CartItemCond, _CartItemCommon); export type CartItem = z.infer<typeof _CartItem>;
and in form component:
let data = superValidateSync(initialValues, _CartItem)
The text was updated successfully, but these errors were encountered:
discriminatedUnion complicates the types a lot and seems to be deprecated in zod soon. Read about it here: #197
Sorry, something went wrong.
No branches or pull requests
I am trying to create schema with conditional fields and I get:
Fragment of my code:
and in form component:
The text was updated successfully, but these errors were encountered: