8000 fix(types): Make `ErrorResponse` type a `StandardSchema` so input par… · aklinker1/zeta@2b412d8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2b412d8

Browse files
committed
fix(types): Make ErrorResponse type a StandardSchema so input params are parsed correctly
1 parent 320daf2 commit 2b412d8

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎src/__tests__/types.test.ts‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { expectTypeOf } from "expect-type";
33
import type * as t from "../types";
44
import { z } from "zod/v4";
55
import type { StandardSchemaV1 } from "@standard-schema/spec";
6+
import type { ErrorResponse } from "../error-response";
67

78
describe("Types", () => {
89
describe("MergeRoutes", () => {
@@ -127,7 +128,7 @@ describe("Types", () => {
127128
});
128129

129130
describe("GetRequestParamsInputFromDef", () => {
130-
it("should get input type for all fields, ignoring response", () => {
131+
it("should get input type for all fields, ignoring a single response", () => {
131132
type Def = {
132133
query: z.ZodObject<{ asc: z.ZodCoercedBoolean<string> }>;
133134
params: z.ZodObject<{ id: z.ZodString }>;
@@ -147,6 +148,27 @@ describe("Types", () => {
147148
expectTypeOf<Actual>().toEqualTypeOf<Expected>();
148149
});
149150

151+
it("should get input type for all fields, ignoring multiple responses", () => {
152+
type Def = {
153+
query: z.ZodObject<{ asc: z.ZodCoercedBoolean<string> }>;
154+
params: z.ZodObject<{ id: z.ZodString }>;
155+
body: z.ZodObject<{ id: z.ZodString; user: z.ZodString }>;
156+
responses: {
157+
200: z.ZodArray<z.ZodObject<{ id: z.ZodString; user: z.ZodString }>>;
158+
400: ErrorResponse;
159+
};
160+
};
161+
type Expected = {
162+
query: { asc: string };
163+
params: { id: string };
164+
body: { id: string; user: string };
165+
};
166+
167+
type Actual = t.GetRequestParamsInputFromDef<Def>;
168+
169+
expectTypeOf<Actual>().toEqualTypeOf<Expected>();
170+
});
171+
150172
it("should include only the body", () => {
151173
type Def = {
152174
body: z.ZodObject<{ id: z.ZodString; user: z.ZodString }>;

‎src/error-response.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const ErrorResponse: StandardSchemaV1 = {
6565
/**
6666
* The actual type an error response conforms to.
6767
*/
68-
export type ErrorResponse = {
68+
export type ErrorResponse = StandardSchemaV1 & {
6969
[additionalInfo: string]: any;
7070
name: string;
7171
message: string;

0 commit comments

Comments
 (0)
0