Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Not assignable to parameter of type 'ZodType<any, ZodTypeDef, any>' error on toTypedSchema #4745

Closed
5 tasks done
nhchoi98 opened this issue May 13, 2024 · 1 comment
Closed
5 tasks done

Comments

@nhchoi98
Copy link

nhchoi98 commented May 13, 2024

What happened?

  • Typescript version: 5.4.5
  • Vee-validate version: 4.12.7
  • Zod version: 3.23.8
const validationSchema = toTypedSchema(testSchema);

When I pass the value through toTypedSchema

  const testSchema = z.object({
    email: z.string().email()
  });

I got this typescript error

Argument of type 'ZodObject<{ email: ZodString; }, "strip", ZodTypeAny, { email: string; }, { email: string; }>' is not assignable to parameter of type 'ZodType<any, ZodTypeDef, any>'.
  The types of '_def.errorMap' are incompatible between these types.ts(2345)

and, same on

  import { object } from 'zod';

  const testSchema = toTypedSchema(
    object({
      email: string().email()
    })
  );

This results below error, slowing down whole IDE.

Type instantiation is excessively deep and possibly infinite.ts(2589)

But, When I declare type and specify type when I use useForm like below

 import { toTypedSchema } from '@vee-validate/zod';
  import { useForm } from 'vee-validate';
  import { z } from 'zod';

  const validationSchema = z.object({
    email: z.string().email()
  });

  type Test = typeof validationSchema;

  const testSchema = toTypedSchema(validationSchema);


  const { errors } = useForm<Test>({ validationSchema: testSchema });

Type instantiation is excessively deep and possibly infinite.ts(2589), which result slowing down IDE disappear gone but still Argument of type 'ZodObject<{ email: ZodString; }, "strip", ZodTypeAny, { email: string; }, { email: string; }>' is not assignable to parameter of type 'ZodType<any, ZodTypeDef, any>'.
The types of '_def.errorMap' are incompatible between these types.ts(2345)
error remains.

Reproduction steps

  1. Add below codes.
  import { toTypedSchema } from '@vee-validate/zod';
  import { useForm } from 'vee-validate';
  import { z } from 'zod';

  const testSchema = toTypedSchema(
    z.object({
      email: string().email()
    })
  );

  const { errors } = useForm({ validationSchema: testSchema });
  1. Additional experiments also doesn't work for me, (refer Add a computed ref in useForm that contains the submitted form data #4275)
  import { toTypedSchema } from '@vee-validate/zod';
  import { useForm } from 'vee-validate';
  import { z } from 'zod';

  const schema = z.object({
    email: z.string().min(1)
  });

  type Input = z.input<typeof schema>;
  type Output = z.infer<typeof schema>;

  const { values } = useForm({
    validationSchema: toTypedSchema<typeof schema, Output, Input>(schema)
  });

, result

Argument of type 'ZodObject<{ email: ZodString; }, "strip", ZodTypeAny, { email: string; }, { email: string; }>' is not assignable to parameter of type 'ZodType<any, ZodTypeDef, any>'.
  The types of '_def.errorMap' are incompatible between these types.ts(2345)

Version

Vue.js 3.x and vee-validate 4.x

What browsers are you seeing the problem on?

  • Firefox
  • Chrome
  • Safari
  • Microsoft Edge

Relevant log output

No response

Demo link

Code of Conduct

@nhchoi98 nhchoi98 changed the title Not assignable to parameter of type 'ZodType<any, ZodTypeDef, any>' Not assignable to parameter of type 'ZodType<any, ZodTypeDef, any>' error on toTypedSchema May 13, 2024
@nhchoi98
Copy link
Author

nhchoi98 commented May 13, 2024

I found that there's no error on below package.json cofiguration.

"vee-validate": "4.12.7"
"@vee-validate/zod": "4.10.8",
 "zod": "3.23.8",
"zod": "3.23.8",
"vue": "3.4.26",

Repository owner locked and limited conversation to collaborators May 28, 2024
@logaretm logaretm converted this issue into discussion #4760 May 28, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant