Type guard for t.discriminatedUnion #3689
Unanswered
PatrickRose
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm attempting to use discriminated unions for some of the new feature we're doing. I'd written the following code but I get a TS error
However, I get told:
parsedData
is possiblyundefined
(which I wasn't expecting).result
/.error
don't exist on the type, because the compiler still treats it as{'status: 'success', result: z.infer<Success>} | {'status: 'failure', result: z.infer<Failure>}
, even though there's theif
conditionalBeta Was this translation helpful? Give feedback.
All reactions