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

Getting typescript build error with the new discriminated union output (v1.6.1) #110

Open
ronaldcurtis opened this issue Apr 2, 2023 · 5 comments

Comments

@ronaldcurtis
Copy link

ronaldcurtis commented Apr 2, 2023

Playground Link: Here

Error output:

error TS2740: Type 'ZodIntersection<ZodObject<{ path: ZodString; value: ZodObject<{}, "strip", ZodTypeAny, {}, {}>; }, "strip", ZodTypeAny, { path: string; value: {}; }, { path: string; value: {}; }>, ZodObject<...>>' is missing the following properties from type 'ZodObject<{ op: ZodTypeAny; } & ZodRawShape, UnknownKeysParam, ZodTypeAny, { [x: string]: any; op?: any; }, { [x: string]: any; op?: any; }>': _cached, _getCached, shape, strict, and 14 more.

Hi there, we seem to be getting an error with the latest release (v1.6.1) with the introduced z.discriminatedUnion output. We have an implementation of JSONPatch on one of our open-API endpoints, and the error seems to be centered around this.

Any help is appreciated! 🙏

Screen Shot 2023-04-03 at 1 53 08 pm

@ronaldcurtis ronaldcurtis changed the title Getting typescript build error with the new discriminated union output Getting typescript build error with the new discriminated union output (v1.6.1) Apr 2, 2023
@astahmer
Copy link
Owner

astahmer commented Apr 4, 2023

hey, @dominik-parkopedia any idea on what's needed to fix this ? mentioning you since you introduced z.discriminatedUnion here

@dominik-parkopedia
Copy link
Contributor

@astahmer @ronaldcurtis Very interesting … Sorry for breaking your build! I won't have time today, but will have a look tomorrow. Seems like we have to increase test coverage.

@ronaldcurtis
Copy link
Author

ronaldcurtis commented Apr 10, 2023

@astahmer @dominik-parkopedia Looks like this is a known problem: colinhacks/zod#2121

Also disciminatedUnion is being deprecated: colinhacks/zod#2109

TLDR:

z.discrimininatedUnion is too fragile and causes too much confusion so it needs to go.

Perhaps it might be worth reverting the change? And introduce the new z.switch function when it becomes available?

@astahmer
Copy link
Owner

that's fine with me 👍 thanks for the investigation btw

@dominik-parkopedia
Copy link
Contributor

Sorry for only coming back today. I will have a look at that!

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

3 participants