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

Feature request: Support pick on unions, using shared properties (just like in TS) #3899

Open
alexbjorlig opened this issue Dec 10, 2024 · 0 comments

Comments

@alexbjorlig
Copy link

const someType = z.union([
    z.object({shared: z.number(), foo: z.array(z.string()) }),
    z.object({shared: z.number() })
  ])

type SomeType = z.infer<typeof someType>;

type ThisTypeWorksInTs = Pick<SomeType, 'shared'>;

/*
Gives error Property 'pick' does not exist on type
'ZodUnion<[ZodObject<{ shared: ZodNumber; foo: ZodArray<ZodString, "many">; },
"strip", ZodTypeAny, { shared: number; foo: string[]; }, { shared: number; foo: string[]; }>,
ZodObject<...>]>'.ts(2339)
*/
const butDoesNotWorkInZod = someType.pick({ shared: true });
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

1 participant