Skip to content
Myr

fix(types): `app.use(path, mw)` return correct schema type (#3128)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Yusuke Wada · committed by GitHub · parent f1c7d31 · Browse files · 3 files+21 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Ame_x <121654029+EdamAme-x@users.noreply.github.com>

Diff stats

3 files+21 added−2 removed

  • tests:+15 added−0 removed
  • other:+6 added−2 removed

3 files+21 added−2 removed

modified:src/helper/factory/index.ts+5 added-1 removed
239 unmodified lines
240export const createFactory = <E extends Env = any, P extends string = any>(init?: {241 initApp?: InitApp<E>242}): Factory<E, P> => new Factory<E, P>(init)243244export const createMiddleware = <E extends Env = any, P extends string = any, I extends Input = {}>(244export const createMiddleware = <245 E extends Env = any,246 P extends string = string,247 I extends Input = {}248>(249 middleware: MiddlewareHandler<E, P, I>250): MiddlewareHandler<E, P, I> => createFactory<E, P>().createMiddleware<I>(middleware)
modified:src/types.test.ts+15 added
2223 unmodified lines
2224 return c.json(0)2225 })2226 })2227})22282229// https://github.com/honojs/hono/issues/31222230describe('Returning type from `app.use(path, mw)`', () => {2231 const mw = createMiddleware(async (c, next) => {2232 await next()2233 })2234 it('Should not mark `*` as never', () => {2235 const app = new Hono().use('*', mw)2236 type Actual = ExtractSchema<typeof app>2237 type Expected = {2238 '*': {}2239 }2240 type verify = Expect<Equal<Expected, Actual>>2241 })2242})
modified:src/types.ts+1 added-1 removed
1802 unmodified lines
1803 }1804}18051806type ChangePathOfSchema<S extends Schema, Path extends string> = keyof S extends never1807 ? { [K in Path]: never }1807 ? { [K in Path]: {} }1808 : { [K in keyof S as Path]: S[K] }18091810export type Endpoint = {1811 input: Partial<ValidationTargets>
198 unmodified lines