Skip to content
This repository has been archived by the owner on May 6, 2023. It is now read-only.

Typescript errors with createType zod versions != 3.17.10 #204

Open
donalffons opened this issue Mar 10, 2023 · 13 comments
Open

Typescript errors with createType zod versions != 3.17.10 #204

donalffons opened this issue Mar 10, 2023 · 13 comments

Comments

@donalffons
Copy link

Thank you for this great package! I've been enjoying using it a lot!

Here is my issue: When I copy the example code for createType into my project / code editor (VS code), it takes a very long time to do perform type checking and then eventually fails with multiple instances of the error "Type instantiation is excessively deep and possibly infinite". It doesn't happen with older zod versions.

image

@donalffons
Copy link
Author

oh well, the same thing happens if I use an older zod version - I just tested 3.16.1. Maybe that means that my zod version has to match the one used by this package?!

@donalffons donalffons changed the title Typescript errors with createType zod versions >= 3.18.0 Typescript errors with createType zod versions != 3.17.10 Mar 10, 2023
@saiichihashimoto
Copy link
Owner

I'm not able to repro this. Are you able to create a minimal repro that illustrates what you're talking about?

I also haven't tested this with various versions of zod. There might be a better way to include/use zod in this library, but I haven't tried anything.

@DanielMontilla
Copy link

DanielMontilla commented Apr 9, 2023

matching zod version (3.17.10) fixed it for me. Heres a repo to reproduce it.

@saiichihashimoto
Copy link
Owner

This is hard to solve. zod is bundled with this package on purpose, so it will always be a specific version of zod. I could make it a peerDependency, but I'd like to avoid that. Are you using zod for other reasons or are you installing it specifically for this library?

@DanielMontilla
Copy link

I'm also using zod for other stuff but reverting to the old version didn't seem to break anything

@donalffons
Copy link
Author

Apologies for the late reply and thanks a lot for looking into this. This issue isn't critical for me any more - I decided to work around this issue by avoiding to use custom types.
Unfortunately, I can't think of any better solution, at the moment.

@danteissaias
Copy link

This is hard to solve. zod is bundled with this package on purpose, so it will always be a specific version of zod. I could make it a peerDependency, but I'd like to avoid that. Are you using zod for other reasons or are you installing it specifically for this library?

Is there a reason to avoid making it a peer dependency?

@donalffons
Copy link
Author

Is there a reason to avoid making it a peer dependency?

I would assume that setting the exact version as a peerDependency would force the package manager to always resolve to that specific version of zod. If other packages require slightly different versions, the package manager might fail to resolve. This would prevent users from using this library in their projects, even though they might never run into the problem described above (since this problem only occurs once you start using createType).
That's my understanding, but certainly @saiichihashimoto knows best 🙂.

@saiichihashimoto
Copy link
Owner

I doubt it'll end up mattering too much if I make zod a peerDependency, although it's asking someone to install zod when they may not need to, which is always a bit annoying. My bigger qualm is that I'm not sure why it's causing a collision at all. Shouldn't this package just use it's own version of zod and not collide? Not sure what's going on.

@danteissaias
Copy link

I doubt it'll end up mattering too much if I make zod a peerDependency, although it's asking someone to install zod when they may not need to, which is always a bit annoying. My bigger qualm is that I'm not sure why it's causing a collision at all. Shouldn't this package just use it's own version of zod and not collide? Not sure what's going on.

I’m using pnpm, might be an issue with how pnpm constructs node_modules?

@mckelveygreg
Copy link
Contributor

I'm in a monorepo with other packages using zod, so if I use an exported schema in another package to combine it with that package's zod, that dependent package must also have the same version or zod is unhappy...

@saiichihashimoto
Copy link
Owner

@danteissaias, are you able to see if using npm directly has the same issue in your project? I'm curious if there's an pnpm specific problem here.

@danteissaias
Copy link

This got fixed for me by upgrading to the latest versions of both zod and sanity-typed-schema builder. 👍

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

No branches or pull requests

5 participants