diff --git a/src/helper/factory/index.ts b/src/helper/factory/index.ts index 42e702f72..041b6e24b 100644 --- a/src/helper/factory/index.ts +++ b/src/helper/factory/index.ts @@ -241,6 +241,10 @@ export const createFactory = (init? initApp?: InitApp }): Factory => new Factory(init) -export const createMiddleware = ( +export const createMiddleware = < + E extends Env = any, + P extends string = string, + I extends Input = {} +>( middleware: MiddlewareHandler ): MiddlewareHandler => createFactory().createMiddleware(middleware) diff --git a/src/types.test.ts b/src/types.test.ts index eafd26837..c94d1b65d 100644 --- a/src/types.test.ts +++ b/src/types.test.ts @@ -2225,3 +2225,18 @@ describe('Env types and a path type with `app.use(path, handler...)` - test only }) }) }) + +// https://github.com/honojs/hono/issues/3122 +describe('Returning type from `app.use(path, mw)`', () => { + const mw = createMiddleware(async (c, next) => { + await next() + }) + it('Should not mark `*` as never', () => { + const app = new Hono().use('*', mw) + type Actual = ExtractSchema + type Expected = { + '*': {} + } + type verify = Expect> + }) +}) diff --git a/src/types.ts b/src/types.ts index e6f3cdeb6..d8b7ba4be 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1804,7 +1804,7 @@ export type Schema = { } type ChangePathOfSchema = keyof S extends never - ? { [K in Path]: never } + ? { [K in Path]: {} } : { [K in keyof S as Path]: S[K] } export type Endpoint = {