8000 fix(types): Properly build request context type · aklinker1/zeta@c4922f0 · GitHub
[go: up one dir, main page]

Skip to content

Commit c4922f0

Browse files
committed
fix(types): Properly build request context type
1 parent 3469080 commit c4922f0

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

‎src/__tests__/types.test.ts‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ describe("Types", () => {
410410
expectTypeOf<Actual>().toMatchObjectType<Expected>();
411411
});
412412

413-
it("should some base parameters for all handlers", () => {
413+
it("should include some base parameters for all handlers", () => {
414414
type Path = "/api";
415415
type Def = t.AnyDef;
416416
type Ctx = { a: "A" };
@@ -432,6 +432,39 @@ describe("Types", () => {
432432
type Actual = t.BuildHandlerContext<App, Path, Def>;
433433
expectTypeOf<Actual>().toMatchObjectType<Expected>();
434434
});
435+
436+
it("should build input params correctly", () => {
437+
type Path = "/api";
438+
type Def = {
439+
body: z.ZodObject<{ body: z.ZodString }>;
440+
query: z.ZodObject<{ query: z.ZodNumber }>;
441+
params: z.ZodObject<{ params: z.ZodBoolean }>;
442+
responses: {
443+
404: ErrorResponse;
444+
};
445+
};
446+
type Ctx = { a: "A" };
447+
type App = {
448+
prefix: "";
449+
exported: false;
450+
ctx: Ctx;
451+
routes: {
452+
GET: {
453+
[p in Path]: Def;
454+
};
455+
};
456+
};
457+
type Expected = {
458+
route: Path;
459+
request: Request;
460+
body: { body: string };
461+
query: { query: number };
462+
params: { params: boolean };
463+
};
464+
465+
type Actual = t.BuildHandlerContext<App, Path, Def>;
466+
expectTypeOf<Actual>().toMatchObjectType<Expected>();
467+
});
435468
});
436469

437470
describe("ApplyAppPrefix", () => {

‎src/types.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,10 @@ export type BuildHandlerContext<
751751
TPath extends BasePath,
752752
TRouteDef extends RouteDef,
753753
> = Simplify<
754-
OnBeforeHandleContext<GetAppDataCtx<TAppData>> & {
754+
Omit<
755+
OnBeforeHandleContext<GetAppDataCtx<TAppData>>,
756+
"body" | "query" | "params" | "headers"
757+
> & {
755758
route: TPath;
756759
} & GetRequestParamsOutputFromDef<TRouteDef> & {
757760
status: StatusFn<GetResponseStatusMap<TRouteDef>>;

0 commit comments

Comments
 (0)
0