mirror of
https://github.com/honojs/hono.git
synced 2024-11-21 18:18:57 +01:00
fix(types): app.use(path, mw)
return correct schema type (#3128)
Co-authored-by: Ame_x <121654029+EdamAme-x@users.noreply.github.com>
This commit is contained in:
parent
f1c7d312a8
commit
642dd29666
@ -241,6 +241,10 @@ export const createFactory = <E extends Env = any, P extends string = any>(init?
|
||||
initApp?: InitApp<E>
|
||||
}): Factory<E, P> => new Factory<E, P>(init)
|
||||
|
||||
export const createMiddleware = <E extends Env = any, P extends string = any, I extends Input = {}>(
|
||||
export const createMiddleware = <
|
||||
E extends Env = any,
|
||||
P extends string = string,
|
||||
I extends Input = {}
|
||||
>(
|
||||
middleware: MiddlewareHandler<E, P, I>
|
||||
): MiddlewareHandler<E, P, I> => createFactory<E, P>().createMiddleware<I>(middleware)
|
||||
|
@ -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<typeof app>
|
||||
type Expected = {
|
||||
'*': {}
|
||||
}
|
||||
type verify = Expect<Equal<Expected, Actual>>
|
||||
})
|
||||
})
|
||||
|
@ -1804,7 +1804,7 @@ export type Schema = {
|
||||
}
|
||||
|
||||
type ChangePathOfSchema<S extends Schema, Path extends string> = keyof S extends never
|
||||
? { [K in Path]: never }
|
||||
? { [K in Path]: {} }
|
||||
: { [K in keyof S as Path]: S[K] }
|
||||
|
||||
export type Endpoint = {
|
||||
|
Loading…
Reference in New Issue
Block a user