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

Transformed objects in .union() vs .discriminatedUnion() #1424

Closed
elmeister opened this issue Sep 24, 2022 · 2 comments
Closed

Transformed objects in .union() vs .discriminatedUnion() #1424

elmeister opened this issue Sep 24, 2022 · 2 comments
Labels
stale No activity in last 60 days

Comments

@elmeister
Copy link

Hello, thanks for the amazing package
I noticed that for the following two objects, first of which is transformed

const TransformedObject = z.object({ a: z.literal('1') }).transform(val => val);
const AnotherObject = z.object({ a: z.literal('2') });

.union() will work just fine

const Union = z.union([TransformedObject, AnotherObject]);

While .discriminatedUnion()

const DiscriminatedUnion = z.discriminatedUnion('a', [TransformedObject, AnotherObject]);

Will produce the following error

Type 'ZodEffects<...>' is missing the following properties from type 'ZodObject<...>': 
_cached, _getCached, shape, strict, and 14 more.

So the question is to find out whether transformed objects shouldn't be used in .union(), or something is wrong with the input type check of the .discriminatedUnion()

@roblabat
Copy link
Contributor

roblabat commented Oct 28, 2022

Seems to be related to #1171 with the openned PR #1290 fixing this issue and waiting for feed back or merge.

@stale
Copy link

stale bot commented Jan 26, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale No activity in last 60 days label Jan 26, 2023
@stale stale bot closed this as completed Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale No activity in last 60 days
Projects
None yet
Development

No branches or pull requests

2 participants