Zod inferred union type does not work properly; 'hackerProfile' does not exist on type...

Typescript is telling me that hackerProfile, partnerProfile, and mentorProfile don't exist on my UpdateUserInput, which I inferred from Zod. Even though I can see hackerProfile, partnerProfile, and mentorProfile in the type when I hoer my cursor over it in VS code. It doesn't seem to have a problem with userUpdate. What's going on here? https://github.com/currenthandle/next-apollo/blob/working-state/server/src/utils/validators.ts#L76 https://github.com/currenthandle/next-apollo/blob/working-state/server/src/graphql/resolvers/mutations.ts#L28
2 Replies
Brendonovich
Brendonovich2y ago
I don't think typescript will let you destructure a discriminated union, u have to use if/switch to narrow to one variant at a time and then grab the values you need
Want results from more Discord servers?
Add your server