From 964aa549c1d59dcceb508f164517d68a6791c4a9 Mon Sep 17 00:00:00 2001 From: m-shaka Date: Tue, 29 Oct 2024 15:25:10 +0900 Subject: [PATCH] fix(types): replace Hono with HonoBase to get better consistency of types (#3580) --- src/types.ts | 142 ++++++++++++++++++++++++++------------------------- 1 file changed, 73 insertions(+), 69 deletions(-) diff --git a/src/types.ts b/src/types.ts index 09bfeb97..101eed7f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -6,7 +6,7 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-explicit-any */ import type { Context } from './context' -import type { Hono } from './hono' +import type { HonoBase } from './hono-base' import type { CustomHeader, RequestHeader } from './utils/headers' import type { StatusCode } from './utils/http-status' import type { @@ -119,7 +119,7 @@ export interface HandlerInterface< E2 extends Env = E >( handler: H - ): Hono, S & ToSchema>, BasePath> + ): HonoBase, S & ToSchema>, BasePath> // app.get(handler x2) < @@ -131,7 +131,7 @@ export interface HandlerInterface< E3 extends Env = IntersectNonAnyTypes<[E, E2]> >( ...handlers: [H, H] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3]>, S & ToSchema>, BasePath @@ -147,7 +147,7 @@ export interface HandlerInterface< >( path: P, handler: H - ): Hono, I, MergeTypedResponse>, BasePath> + ): HonoBase, I, MergeTypedResponse>, BasePath> // app.get(handler x 3) < @@ -161,7 +161,7 @@ export interface HandlerInterface< E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]> >( ...handlers: [H, H, H] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4]>, S & ToSchema>, BasePath @@ -179,7 +179,7 @@ export interface HandlerInterface< >( path: P, ...handlers: [H, H] - ): Hono, I2, MergeTypedResponse>, BasePath> + ): HonoBase, I2, MergeTypedResponse>, BasePath> // app.get(handler x 4) < @@ -195,7 +195,7 @@ export interface HandlerInterface< E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]> >( ...handlers: [H, H, H, H] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, S & ToSchema>, BasePath @@ -215,7 +215,7 @@ export interface HandlerInterface< >( path: P, ...handlers: [H, H, H] - ): Hono, I3, MergeTypedResponse>, BasePath> + ): HonoBase, I3, MergeTypedResponse>, BasePath> // app.get(handler x 5) < @@ -233,7 +233,7 @@ export interface HandlerInterface< E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]> >( ...handlers: [H, H, H, H, H] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, S & ToSchema>, BasePath @@ -260,7 +260,7 @@ export interface HandlerInterface< H, H ] - ): Hono, I4, MergeTypedResponse>, BasePath> + ): HonoBase, I4, MergeTypedResponse>, BasePath> // app.get(handler x 6) < @@ -287,7 +287,7 @@ export interface HandlerInterface< H, H ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, S & ToSchema>, BasePath @@ -317,7 +317,7 @@ export interface HandlerInterface< H, H ] - ): Hono, I5, MergeTypedResponse>, BasePath> + ): HonoBase, I5, MergeTypedResponse>, BasePath> // app.get(handler x 7) < @@ -347,7 +347,7 @@ export interface HandlerInterface< H, H ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, S & ToSchema>, BasePath @@ -380,7 +380,7 @@ export interface HandlerInterface< H, H ] - ): Hono, I6, MergeTypedResponse>, BasePath> + ): HonoBase, I6, MergeTypedResponse>, BasePath> // app.get(handler x 8) < @@ -413,7 +413,7 @@ export interface HandlerInterface< H, H ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, S & ToSchema>, BasePath @@ -449,7 +449,7 @@ export interface HandlerInterface< H, H ] - ): Hono, I7, MergeTypedResponse>, BasePath> + ): HonoBase, I7, MergeTypedResponse>, BasePath> // app.get(handler x 9) < @@ -485,7 +485,7 @@ export interface HandlerInterface< H, H ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>, S & ToSchema>, BasePath @@ -524,7 +524,7 @@ export interface HandlerInterface< H, H ] - ): Hono, I8, MergeTypedResponse>, BasePath> + ): HonoBase, I8, MergeTypedResponse>, BasePath> // app.get(handler x 10) < @@ -563,7 +563,7 @@ export interface HandlerInterface< H, H ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>, S & ToSchema>, BasePath @@ -605,7 +605,7 @@ export interface HandlerInterface< H, H ] - ): Hono, I9, MergeTypedResponse>, BasePath> + ): HonoBase, I9, MergeTypedResponse>, BasePath> // app.get(path, handler x10) < @@ -646,7 +646,7 @@ export interface HandlerInterface< H, H ] - ): Hono, I10, MergeTypedResponse>, BasePath> + ): HonoBase, I10, MergeTypedResponse>, BasePath> // app.get(...handlers[]) < @@ -655,18 +655,18 @@ export interface HandlerInterface< R extends HandlerResponse = any >( ...handlers: H[] - ): Hono>, BasePath> + ): HonoBase>, BasePath> // app.get(path, ...handlers[])

= any>( path: P, ...handlers: H, I, R>[] - ): Hono, I, MergeTypedResponse>, BasePath> + ): HonoBase, I, MergeTypedResponse>, BasePath> // app.get(path)

= any, I extends Input = BlankInput>( path: P - ): Hono, I, MergeTypedResponse>, BasePath> + ): HonoBase, I, MergeTypedResponse>, BasePath> } //////////////////////////////////////// @@ -683,12 +683,12 @@ export interface MiddlewareHandlerInterface< //// app.use(...handlers[]) ( ...handlers: MiddlewareHandler>>[] - ): Hono, S, BasePath> + ): HonoBase, S, BasePath> // app.use(handler) ( handler: MiddlewareHandler>> - ): Hono, S, BasePath> + ): HonoBase, S, BasePath> // app.use(handler x2) < @@ -697,7 +697,7 @@ export interface MiddlewareHandlerInterface< P extends string = MergePath> >( ...handlers: [MiddlewareHandler, MiddlewareHandler] - ): Hono, S, BasePath> + ): HonoBase, S, BasePath> // app.get(path, handler) < @@ -707,7 +707,7 @@ export interface MiddlewareHandlerInterface< >( path: P, handler: MiddlewareHandler - ): Hono, ChangePathOfSchema, BasePath> + ): HonoBase, ChangePathOfSchema, BasePath> // app.use(handler x3) < @@ -717,7 +717,7 @@ export interface MiddlewareHandlerInterface< P extends string = MergePath> >( ...handlers: [MiddlewareHandler, MiddlewareHandler, MiddlewareHandler] - ): Hono, S, BasePath> + ): HonoBase, S, BasePath> // app.get(path, handler x2) < @@ -728,7 +728,7 @@ export interface MiddlewareHandlerInterface< >( path: P, ...handlers: [MiddlewareHandler, MiddlewareHandler] - ): Hono, ChangePathOfSchema, BasePath> + ): HonoBase, ChangePathOfSchema, BasePath> // app.use(handler x4) < @@ -744,7 +744,7 @@ export interface MiddlewareHandlerInterface< MiddlewareHandler, MiddlewareHandler ] - ): Hono, S, BasePath> + ): HonoBase, S, BasePath> // app.get(path, handler x3) < @@ -756,7 +756,7 @@ export interface MiddlewareHandlerInterface< >( path: P, ...handlers: [MiddlewareHandler, MiddlewareHandler, MiddlewareHandler] - ): Hono, ChangePathOfSchema, BasePath> + ): HonoBase, ChangePathOfSchema, BasePath> // app.use(handler x5) < @@ -774,7 +774,7 @@ export interface MiddlewareHandlerInterface< MiddlewareHandler, MiddlewareHandler ] - ): Hono, S, BasePath> + ): HonoBase, S, BasePath> // app.get(path, handler x4) < @@ -792,7 +792,11 @@ export interface MiddlewareHandlerInterface< MiddlewareHandler, MiddlewareHandler ] - ): Hono, ChangePathOfSchema, BasePath> + ): HonoBase< + IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, + ChangePathOfSchema, + BasePath + > // app.use(handler x6) < @@ -812,7 +816,7 @@ export interface MiddlewareHandlerInterface< MiddlewareHandler, MiddlewareHandler ] - ): Hono, S, BasePath> + ): HonoBase, S, BasePath> // app.get(path, handler x5) < @@ -832,7 +836,7 @@ export interface MiddlewareHandlerInterface< MiddlewareHandler, MiddlewareHandler ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, ChangePathOfSchema, BasePath @@ -858,7 +862,7 @@ export interface MiddlewareHandlerInterface< MiddlewareHandler, MiddlewareHandler ] - ): Hono, S, BasePath> + ): HonoBase, S, BasePath> // app.get(path, handler x6) < @@ -880,7 +884,7 @@ export interface MiddlewareHandlerInterface< MiddlewareHandler, MiddlewareHandler ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, ChangePathOfSchema, BasePath @@ -908,7 +912,7 @@ export interface MiddlewareHandlerInterface< MiddlewareHandler, MiddlewareHandler ] - ): Hono, S, BasePath> + ): HonoBase, S, BasePath> // app.get(path, handler x7) < @@ -932,7 +936,7 @@ export interface MiddlewareHandlerInterface< MiddlewareHandler, MiddlewareHandler ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, ChangePathOfSchema, BasePath @@ -962,7 +966,7 @@ export interface MiddlewareHandlerInterface< MiddlewareHandler, MiddlewareHandler ] - ): Hono, S, BasePath> + ): HonoBase, S, BasePath> // app.get(path, handler x8) < @@ -988,7 +992,7 @@ export interface MiddlewareHandlerInterface< MiddlewareHandler, MiddlewareHandler ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, ChangePathOfSchema, BasePath @@ -1020,7 +1024,7 @@ export interface MiddlewareHandlerInterface< MiddlewareHandler, MiddlewareHandler ] - ): Hono, S, BasePath> + ): HonoBase, S, BasePath> // app.get(path, handler x9) < @@ -1048,7 +1052,7 @@ export interface MiddlewareHandlerInterface< MiddlewareHandler, MiddlewareHandler ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>, ChangePathOfSchema, BasePath @@ -1058,7 +1062,7 @@ export interface MiddlewareHandlerInterface<

( path: P, ...handlers: MiddlewareHandler>[] - ): Hono + ): HonoBase } //////////////////////////////////////// @@ -1084,7 +1088,7 @@ export interface OnHandlerInterface< method: M, path: P, handler: H - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2]>, S & ToSchema, I, MergeTypedResponse>, BasePath @@ -1104,7 +1108,7 @@ export interface OnHandlerInterface< method: M, path: P, ...handlers: [H, H] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3]>, S & ToSchema, I2, MergeTypedResponse>, BasePath @@ -1126,7 +1130,7 @@ export interface OnHandlerInterface< method: M, path: P, ...handlers: [H, H, H] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4]>, S & ToSchema, I3, MergeTypedResponse>, BasePath @@ -1155,7 +1159,7 @@ export interface OnHandlerInterface< H, H ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, S & ToSchema, I4, MergeTypedResponse>, BasePath @@ -1187,7 +1191,7 @@ export interface OnHandlerInterface< H, H ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, S & ToSchema, I5, MergeTypedResponse>, BasePath @@ -1222,7 +1226,7 @@ export interface OnHandlerInterface< H, H ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, S & ToSchema, I6, MergeTypedResponse>, BasePath @@ -1260,7 +1264,7 @@ export interface OnHandlerInterface< H, H ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, S & ToSchema, I7, MergeTypedResponse>, BasePath @@ -1301,7 +1305,7 @@ export interface OnHandlerInterface< H, H ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, S & ToSchema, I8, MergeTypedResponse>, BasePath @@ -1345,7 +1349,7 @@ export interface OnHandlerInterface< H, H ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>, S & ToSchema, I9, MergeTypedResponse>, BasePath @@ -1391,7 +1395,7 @@ export interface OnHandlerInterface< H, H ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>, S & ToSchema, I10, MergeTypedResponse>>, BasePath @@ -1407,7 +1411,7 @@ export interface OnHandlerInterface< method: M, path: P, ...handlers: H, I, R>[] - ): Hono, I, MergeTypedResponse>, BasePath> + ): HonoBase, I, MergeTypedResponse>, BasePath> // app.get(method[], path, handler) < @@ -1421,7 +1425,7 @@ export interface OnHandlerInterface< methods: Ms, path: P, handler: H - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2]>, S & ToSchema, I, MergeTypedResponse>, BasePath @@ -1441,7 +1445,7 @@ export interface OnHandlerInterface< methods: Ms, path: P, ...handlers: [H, H] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3]>, S & ToSchema, I2, MergeTypedResponse>, BasePath @@ -1463,7 +1467,7 @@ export interface OnHandlerInterface< methods: Ms, path: P, ...handlers: [H, H, H] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4]>, S & ToSchema, I3, MergeTypedResponse>, BasePath @@ -1492,7 +1496,7 @@ export interface OnHandlerInterface< H, H ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, S & ToSchema, I4, MergeTypedResponse>, BasePath @@ -1524,7 +1528,7 @@ export interface OnHandlerInterface< H, H ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, S & ToSchema, I5, MergeTypedResponse>, BasePath @@ -1559,7 +1563,7 @@ export interface OnHandlerInterface< H, H ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, S & ToSchema, I6, MergeTypedResponse>, BasePath @@ -1597,7 +1601,7 @@ export interface OnHandlerInterface< H, H ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, S & ToSchema, I7, MergeTypedResponse>, BasePath @@ -1638,7 +1642,7 @@ export interface OnHandlerInterface< H, H ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, S & ToSchema, I8, MergeTypedResponse>, BasePath @@ -1681,7 +1685,7 @@ export interface OnHandlerInterface< H, H ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>, S & ToSchema, I9, MergeTypedResponse>>, BasePath @@ -1727,7 +1731,7 @@ export interface OnHandlerInterface< H, H ] - ): Hono< + ): HonoBase< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>, S & ToSchema, I10, MergeTypedResponse>>, BasePath @@ -1738,14 +1742,14 @@ export interface OnHandlerInterface< methods: string[], path: P, ...handlers: H, I, R>[] - ): Hono, I, MergeTypedResponse>, BasePath> + ): HonoBase, I, MergeTypedResponse>, BasePath> // app.on(method | method[], path[], ...handlers[]) = any>( methods: string | string[], paths: string[], ...handlers: H[] - ): Hono>, BasePath> + ): HonoBase>, BasePath> } type ExtractStringKey = keyof S & string @@ -1977,7 +1981,7 @@ export type RemoveQuestion = T extends `${infer R}?` ? R : T //////////////////////////////////////// export type ExtractSchema = UnionToIntersection< - T extends Hono ? S : never + T extends HonoBase ? S : never > type EnvOrEmpty = T extends Env ? (Env extends T ? {} : T) : T