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
Uh oh!
There was an error while loading. Please reload this page.
-
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:No overload matches this call. The last overload gave the following error. Argument of type 'MiddlewareHandler<Env, "/verify", { in: { form: { code: string; }; }; out: { form: { code: string; }; }; }>' is not assignable to parameter of type 'H<Env, "/api/signin/verify", { in: { form: { code: string; }; }; out: { form: { code: string; }; }; }, { otpStatus: "approved"; userId: string; invitedBy: string; cliqId: string; }>'. Type 'MiddlewareHandler<Env, "/verify", { in: { form: { code: string; }; }; out: { form: { code: string; }; }; }>' is not assignable to type 'MiddlewareHandler<Env, "/api/signin/verify", { in: { form: { code: string; }; }; out: { form: { code: string; }; }; }>'. Types of parameters 'c' and 'c' are incompatible. Type 'Context<Env, "/api/signin/verify", { in: { form: { code: string; }; }; out: { form: { code: string; }; }; }>' is not assignable to type 'Context<Env, "/verify", { in: { form: { code: string; }; }; out: { form: { code: string; }; }; }>'. Types of property 'req' are incompatible. Type 'HonoRequest<"/api/signin/verify", { form: { code: string; }; }>' is not assignable to type 'HonoRequest<"/verify", { form: { code: string; }; }>'. Type '"/api/signin/verify"' is not assignable to type '"/verify"'.Beta Was this translation helpful? Give feedback.
All reactions