modular-forms
modular-forms copied to clipboard
Type instantiation is excessively deep and possibly infinite
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
Thanks for creating this issue. Do you know the last version of Modular Forms where this worked without a TS error?
@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.
Is it related to your TS version?
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
I can't reproduce the bug. It seems to work as expected on my machine. 😬
@fabian-hiller what node version are you using? Did you use pnpm?
I'm using node v20.17.0
Yes, [email protected] and [email protected]
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.
https://github.com/juanpmarin/modular-forms-ts-repro/commit/248d61aba0a8819bad8bff6390e595459a104de2#diff-3d4d2177c21702138c6c0473b20d38d819dec2249dd99cbf1d00fde1f6ac5115
Can you try to reproduce it now?
Yes, with import { z } from "@builder.io/qwik-city" the same error happens to me.
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?
I think Qwik should remove the z export and devs should import it directly from Zod.