You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{z}from'zod';exportconstformSchema=z.object({username: z.string().min(2).max(50),confirm: z.string(),}).refine((data)=>data.confirm===data.username,{message: 'Username and confirm must match',path: ['confirm'],});exporttypeFormSchema=typeofformSchema;
I can't assing config to the Form.Field elements:
<scriptlang="ts">import*asFormfrom'$lib/components/ui/form';import{formSchema,typeFormSchema}from'./schema';importtype{SuperValidated}from'sveltekit-superforms';
export letform: SuperValidated<FormSchema>;</script><Form.Rootmethod="POST" {form}schema={formSchema}let:config><!-- Red error on "config" --><Form.Field{config}name="username"><Form.Item><Form.Label>Username</Form.Label><Form.Input/><Form.Validation/></Form.Item></Form.Field><!-- Red error on "config" --><Form.Field{config}name="confirm"><Form.Item><Form.Label>Confirm Username</Form.Label><Form.Input/><Form.Validation/></Form.Item></Form.Field><Form.Button>Submit</Form.Button></Form.Root>
Here's the typescript error for username (sadly it's being cropped by vscode...):
Type '{ form: SuperForm<ZodObject<{ username: ZodString; confirm: ZodString; }, "strip", ZodTypeAny, { username: string; confirm: string; }, { username: string; confirm: string; }>, any>; schema: ZodEffects<...>; }' is not assignable to type 'Form<AnyZodObject>'.
Types of property 'schema' are incompatible.
Type 'ZodEffects<ZodObject<{ username: ZodString; confirm: ZodString; }, "strip", ZodTypeAny, { username: string; confirm: string; }, { username: string; confirm: string; }>, { ...; }, { ...; }>' is missing the following properties from type 'ZodObject<any, any, any, { [x: string]: any; }, { [x: string]: any; }>': _cached, _getCached, shape, strict, and 14 more.ts(2322)
And the typescript error for confirm:
Type '{ form: SuperForm<ZodObject<{ username: ZodString; confirm: ZodString; }, "strip", ZodTypeAny, { username: string; confirm: string; }, { username: string; confirm: string; }>, any>; schema: ZodEffects<...>; }' is not assignable to type 'Form<AnyZodObject>'.ts(2322)
Note: the client-side validation seems to still be working. It might be a typescript only issue.
The text was updated successfully, but these errors were encountered:
BenocxX
changed the title
Impossible to assign "config" to field when the Zod schema has a "refine"
Impossible to assign "config" to Form.Field when the Zod schema has a "refine"
Sep 17, 2023
With the following schema:
I can't assing
config
to theForm.Field
elements:Here's the typescript error for
username
(sadly it's being cropped by vscode...):And the typescript error for
confirm
:Note: the client-side validation seems to still be working. It might be a typescript only issue.
I did the experiment in a fresh Sveltekit projet. I followed the shadcn-svelte installation guide and I reproduced the simple Form component example.
You can see the whole repo here.
Thanks for the help :)
The text was updated successfully, but these errors were encountered: