Skip to content
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

Type instantiation is excessively deep and possibly infinite #256

Open
juanpmarin opened this issue Oct 8, 2024 · 11 comments
Open

Type instantiation is excessively deep and possibly infinite #256

juanpmarin opened this issue Oct 8, 2024 · 11 comments
Assignees
Labels
question Further information is requested

Comments

@juanpmarin
Copy link

Hi!
I'm using [email protected] and @modular-forms/[email protected].

I just bootstrapped a new application trying to find why typescript compilation was taking much longer for one of my projects.

For this simple setup:

import { formAction$, zodForm$ } from "@modular-forms/qwik";
import { z } from "zod";

const userInfoSchema = z.object({
  fullName: z.string(),
  phone: z.string(),
  company: z.string(),
});

type UserInfoForm = z.input<typeof userInfoSchema>;

export const useFormAction = formAction$<UserInfoForm>(async (userInfo) => {
  console.log(userInfo);
}, zodForm$(userInfoSchema));

I get the following error:

src/routes/index.tsx:19:4 - error TS2589: Type instantiation is excessively deep and possibly infinite.

21 }, zodForm$(userInfoSchema));
      ~~~~~~~~~~~~~~~~~~~~~~~~


Found 1 error in src/routes/index.tsx:21
@fabian-hiller
Copy link
Owner

Thanks for creating this issue. Do you know the last version of Modular Forms where this worked without a TS error?

@fabian-hiller fabian-hiller added the question Further information is requested label Oct 8, 2024
@fabian-hiller fabian-hiller self-assigned this Oct 8, 2024
@juanpmarin
Copy link
Author

juanpmarin commented Oct 9, 2024

@fabian-hiller It’s strange; the issue doesn’t appear to be tied to the version of modular-forms.
Even after downgrading modular-forms in a newly initialized project, the problem persists.

@fabian-hiller
Copy link
Owner

Is it related to your TS version?

@juanpmarin
Copy link
Author

juanpmarin commented Oct 10, 2024

At this point I'm not sure what's causing the problem. I've also tried multiple ts versions and the issue persists.

Here's a reproduction repo so you can try it. It's just a fresh qwik repo with a very simple schema.

https://github.com/juanpmarin/modular-forms-ts-repro

You can reproduce the error by running pnpm exec tsc

@fabian-hiller
Copy link
Owner

I can't reproduce the bug. It seems to work as expected on my machine. 😬

@juanpmarin
Copy link
Author

@fabian-hiller what node version are you using? Did you use pnpm?
I'm using node v20.17.0

@fabian-hiller
Copy link
Owner

Yes, [email protected] and [email protected]

@juanpmarin
Copy link
Author

I just found something interesting, it seems that qwik-city re-exports zod, and if you import z from qwik city (because the editor suggests it), the issue appears.

juanpmarin/modular-forms-ts-repro@248d61a#diff-3d4d2177c21702138c6c0473b20d38d819dec2249dd99cbf1d00fde1f6ac5115

Can you try to reproduce it now?

@fabian-hiller
Copy link
Owner

Yes, with import { z } from "@builder.io/qwik-city" the same error happens to me.

@juanpmarin
Copy link
Author

It was a hard one to find and started to happen in newer versions of qwik, do you think is there a way to warn users that pass the wrong instance of zod?

@fabian-hiller
Copy link
Owner

I think Qwik should remove the z export and devs should import it directly from Zod.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants