- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Zod 3.22.2 TS 5.2.2: TS2589: Type instantiation is excessively deep and possibly infinite #2697
Comments
Works just fine for me... https://stackblitz.com/edit/stackblitz-starters-rh62xb?file=src%2Findex.ts |
We have the same issue. Reverting back to the previously used version (3.21.4) solves the issue for us. |
@jcollum-nutrien or @kasleet, |
I've created a reproduction repo: https://github.com/ericallam/zod-3-22-2-type-instantiation I understand that there shouldn't be an expectation for this to work (mixing minor Zod updates) but we're (trigger.dev) running into a bunch of users who are trying to use us with 3.22.2 and not being able to. We could upgrade our packages to 3.22.2 but then 3.21.4 users are forced to upgrade (and there are still more 3.21.4 downloads in the last 7 days than 3.22.2) |
I had this same issue on 3.22.2 but upgrading to 3.22.4 fixed it for me |
@JacobWeisenburger I think @ericallam provided a good example. Currently, we are not able to upgrade to 3.22.0 or 3.22.4 as we get the same exception. Do you have any plans on working on this or does anyone have some hints, so I can try to debug it myself / create a PR? Edit: Other then @ericallam, we were able to upgrade our underlying library from zod 3.21.4 to 3.22.4 as we do not have these constraints. Now it works, so this has something to do with using different zod versions. |
We were struggling with this along with use along with TRPC because we were returning a JsonValue from our procedure. Just throwing it out there in case this helps anyone. |
As far as I've tried; it seems like this error only occurs when unions are inside objects. const un = z.union([
z.object({ h: z.string() }),
z.number(),
z.string(),
z.symbol(),
]);
const un1 = z.object({
u: un,
});
const un2 = z.array(un);
const un3 = z.object({
u: un,
uarr: un2,
});
// Type checks
/*
(OK)
type unt = string | number | symbol | {
h: string;
}
*/
type unt = z.infer<typeof un>;
/*
(Not OK. Union inside object)
type unt1 = {
u: (string | number | symbol | {
h: string;
}) & (string | number | symbol | {
h: string;
} | undefined);
}
*/
type unt1 = z.infer<typeof un1>;
/*
(OK. Union inside array)
type unt2 = (string | number | symbol | {
h: string;
})[]
*/
type unt2 = z.infer<typeof un2>;
/*
(Not OK, Union inside object)
type unt3 = {
u: (string | number | symbol | {
h: string;
}) & (string | number | symbol | {
h: string;
} | undefined);
uarr: (string | number | symbol | {
h: string;
})[];
}
*/
type unt3 = z.infer<typeof un3>; |
I have problems with this as well (typescript: 5.2.2, zod 3.22.4). Things will build fine to begin with in watch mode. But whenever I open a file that has the problematic type definition, it will start failing until I restart the build. |
I found out that this issue may occur when multiple versions of |
Had the same issue with using zod in two different projects. After aligning their versions, the issue disappeared. |
Same here, having version |
Well, it happened to me too in a monolithic repo where I had two different versions: |
+1 on @RobinTail 's answer. Im on Turborepo and had inconsistent Zod versions across the packages and apps. Syncing them fixed it. Thanks. |
Error:
src/handler.ts(64,3): error TS2589: Type instantiation is excessively deep and possibly infinite
Related (both closed): #495 and #577
Tried rimraf node modules and reinstalling. That type seems so simple that I don't see what I can do to simplify it.
Is there a playground that I can pull Zod into to reproduce it?
The text was updated successfully, but these errors were encountered: