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

Error with 3.23.0 combined with package that uses 3.22.4 #3429

Closed
m10rten opened this issue Apr 22, 2024 · 4 comments
Closed

Error with 3.23.0 combined with package that uses 3.22.4 #3429

m10rten opened this issue Apr 22, 2024 · 4 comments

Comments

@m10rten
Copy link
Contributor

m10rten commented Apr 22, 2024

I am getting this error when using z from 3.23.0 with a package that is fixed on 3.22.4:

Type 'ZodDefault<ZodNumber>' is not assignable to type 'ZodType<any, ZodTypeDef, any>'.
  The types of '_def.errorMap' are incompatible between these types.

When rolling back to 3.22.4 everything works again (with reloading the vscode ts-servers).

This goes for anything, not just ZodNumber.

@m10rten
Copy link
Contributor Author

m10rten commented Apr 22, 2024

@colinhacks Could you look into this?

@colinhacks
Copy link
Owner

colinhacks commented Apr 22, 2024

There's not a lot I can do in this case. You really don't want multiple versions floating around. Usually this happens in monorepos when dependencies aren't properly updated across all packages. If there's a problematic package that pinned itself to a specific Zod version, then they'll need to fix that upstream.

What package is this? Do you have a replication?

@m10rten
Copy link
Contributor Author

m10rten commented Apr 23, 2024

It's a private package, but is this then not considered breaking?

Replication is thus not possible.

@colinhacks
Copy link
Owner

All sorts of bad things happen when you have multiple versions of a package in your project, even if there are no breaking changes between the two. This kind of error would happen with any two versions of Zod, even if they're identical.

You can try this yourself. Zod 3.22.4 and 3.22.5 had literally no changes (due to an accidental patch release).

In your package.json:

	"dependencies": {
		"zod-a": "npm:zod@^3.22.4",
		"zod-b": "npm:zod@3.22.5"
	}

And in a .ts file:

import type * as za from "zod-a";
import * as zb from "zod-b";

const schema: za.ZodType<any, any, any> = zb.string();
// Type 'Zod.ZodIssue[]' is not assignable to type 'import("/Users/colinmcd94/Documents/projects/scratch/node_modules/zod-b/lib/ZodError").ZodIssue[]'.

It's possible the recursive nature of ZodIssue is exacerbating this problem, but I'm not sure. And in any case I'm afraid I can't fix that without a far more disruptive change to the error reporting system.

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

No branches or pull requests

2 participants