From 375c98b145560c855f9000c523734bb2d31990c9 Mon Sep 17 00:00:00 2001 From: Yusuke Wada Date: Mon, 1 Jul 2024 22:58:40 +0900 Subject: [PATCH] fix(zod-openapi): remove the type error for the hook (#607) * fix(zod-openapi): remove the type error for the hook * add changeset --- .changeset/honest-shrimps-change.md | 5 +++++ packages/zod-openapi/src/index.ts | 12 +++++++++++- packages/zod-openapi/test/index.test.ts | 3 +-- 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 .changeset/honest-shrimps-change.md diff --git a/.changeset/honest-shrimps-change.md b/.changeset/honest-shrimps-change.md new file mode 100644 index 00000000..2150dfe9 --- /dev/null +++ b/.changeset/honest-shrimps-change.md @@ -0,0 +1,5 @@ +--- +'@hono/zod-openapi': patch +--- + +fix: remove the type error for the hook diff --git a/packages/zod-openapi/src/index.ts b/packages/zod-openapi/src/index.ts index 319540b8..7b89ab1d 100644 --- a/packages/zod-openapi/src/index.ts +++ b/packages/zod-openapi/src/index.ts @@ -322,7 +322,17 @@ export class OpenAPIHono< I, E, P, - RouteConfigToTypedResponse | Response | Promise | void | Promise + R extends { + responses: { + [statusCode: number]: { + content: { + [mediaType: string]: ZodMediaTypeObject + } + } + } + } + ? MaybePromise> | undefined + : MaybePromise> | MaybePromise | undefined > | undefined = this.defaultHook ): OpenAPIHono< diff --git a/packages/zod-openapi/test/index.test.ts b/packages/zod-openapi/test/index.test.ts index c8339ff1..c0c91974 100644 --- a/packages/zod-openapi/test/index.test.ts +++ b/packages/zod-openapi/test/index.test.ts @@ -1019,14 +1019,13 @@ describe('With hc', () => { }, (result, c) => { if (!result.success) { - const res = c.json( + return c.json( { ok: false, source: 'routeHook' as const, }, 400 ) - return res } } )