astahmer / openapi-zod-client

Generate a zodios (typescript http client with zod validation) from an OpenAPI spec (json/yaml)

Home Page:openapi-zod-client.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

ronaldcurtis opened this issue · comments

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

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

@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.

@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?

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

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