RPC Discriminated Union Inferred Type? #1257
Unanswered
stephencweiss
asked this question in
Q&A
Replies: 2 comments
-
FWIW - it seems like the infer guide returns the same thing I get from the RPC types via |
Beta Was this translation helpful? Give feedback.
0 replies
-
One possible approach is to simply not use the const SigninVerifyResponseSuccessSchema = z.object({
...UserSchema.shape,
otpStatus: z.enum(["approved"]),
});
const SignInVerifyBaseResponseSchema = z.object({
otpStatus: z.enum(["pending", "canceled"]),
});
const SigninVerifyResponseSchema = z.union([
SigninVerifyResponseSuccessSchema,
SignInVerifyBaseResponseSchema,
]);
export type SigninVerifyResponseDTO = z.infer<typeof SigninVerifyResponseSchema>; Though - it gets me part of the way there, so this is the general approach I'm taking at the moment. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is there a way to have an inferred discriminated union type in a response for an API?
For example:
Specifically - this works if I only have one
jsonT
, but when I make the second one alsojsonT
, then I get the following type error:Beta Was this translation helpful? Give feedback.
All reactions