pablo-abc / felte

An extensible form library for Svelte, Solid and React
https://felte.dev
MIT License
1.02k stars 43 forks source link

zod validateSchema, validator schema type error #161

Open timonmasberg opened 2 years ago

timonmasberg commented 2 years ago

Describe the bug

validateSchema(schema) and validator(schema) will report a type error with the schema being an ZodObject:

Argument type ZodObject<{password: ZodString, email: ZodString}, "strip", ZodTypeAny, {[k_1 in keyof objectUtil.addQuestionMarks<{[k in keyof {password: ZodString, email: ZodString}]: {password: ZodString, email: ZodString}[k]["_output"]}>]: objectUtil.addQuestionMarks<{[k in keyof {password: ZodString, email: ZodString}]: {password: ZodString, email: ZodString}[k]["_output"]}>[k_1]}, {[k_3 in keyof objectUtil.addQuestionMarks<{[k_2 in keyof {password: ZodString, email: ZodString}]: {password: ZodString, email: ZodString}[k_2]["_input"]}>]: objectUtil.addQuestionMarks<{[k_2 in keyof {password: ZodString, email: ZodString}]: {password: ZodString, email: ZodString}[k_2]["_input"]}>[k_3]}> is not assignable to parameter type ZodSchema 

Which package/s are you using?

@felte/validator-zod

Environment

Version:

To reproduce

        import { validateSchema } from '@felte/validator-zod';
    import { z } from 'zod';

    const schema = z.object({
        email: z.string().email().nonempty(),
        password: z.string().nonempty(),
    });

    const { form } = createForm({
        // ...
        validate: validateSchema(schema),
        // ...
    });

Small reproduction example

No response

Screenshots

No response

Additional context

No response

danielo515 commented 2 years ago

You are doing it wrong. According to docs it shohuld be;

        validate: validator({ schema }),
timonmasberg commented 2 years ago

You are doing it wrong. According to docs it shohuld be;

      validate: validator({ schema }),

Have a closer look:

OR use the validateSchema function directly in the validate option of createForm. (No need to extend Felte).

https://github.com/pablo-abc/felte/tree/main/packages/validator-zod

Your example is not listed there.

danielo515 commented 2 years ago

My example is listed on that same Readme. The Readme is probably outdated, if you check the migration guide of felte you will see that the suggested method is the deprecated one

El lun., 25 jul. 2022 16:19, Timon @.***> escribió:

You are doing it wrong. According to docs it shohuld be;

  validate: validator({ schema }),

Have a closer look:

OR use the validateSchema function directly in the validate option of createForm. (No need to extend Felte).

https://github.com/pablo-abc/felte/tree/main/packages/validator-zod

Your example is not listed there.

— Reply to this email directly, view it on GitHub https://github.com/pablo-abc/felte/issues/161#issuecomment-1194112011, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARKJWJQUG2WXPOL6K6B6VTVV2O6LANCNFSM53YQCWJA . You are receiving this because you commented.Message ID: @.***>