Skip to content
Myr

fix(client): preserve route schema in ApplyGlobalResponse (#4777)

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

* fix(client): preserve route schema in ApplyGlobalResponse * ci: apply automated fixes ---------

authored by Oguma Shunya · committed by GitHub · parent 790c57b · Browse files · 2 files+25 added−3 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: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>

Diff stats

2 files+25 added−3 removed

  • tests:+20 added−0 removed
  • other:+5 added−3 removed

2 files+25 added−3 removed

modified:src/client/client.test.ts+20 added
1820 unmodified lines
1821 type Expected = { users: string[] } | { error: string }18221823 type verify = Expect<Equal<ResponseType, Expected>>1824 })18251826 it('Should keep route() paths when global responses are applied', () => {1827 const users = new Hono().get('/users', (c) => c.json({ users: ['alice', 'bob'] }, 200))1828 const app = new Hono().route('/api', users)18291830 type AppWithGlobalErrors = ApplyGlobalResponse<1831 typeof app,1832 {1833 500: { json: { error: string } }1834 }1835 >18361837 const client = hc<AppWithGlobalErrors>('http://localhost')1838 const req = client.api.users.$get18391840 type ResponseType = InferResponseType<typeof req>1841 type Expected = { users: string[] } | { error: string }18421843 type verify = Expect<Equal<ResponseType, Expected>>1844 })1845})
modified:src/client/types.ts+5 added-3 removed
1import type { Hono } from '../hono'2import type { HonoBase } from '../hono-base'3import type { METHODS, METHOD_NAME_ALL_LOWERCASE } from '../router'4import type { Endpoint, KnownResponseFormat, ResponseFormat, Schema } from '../types'4import type { Endpoint, ExtractSchema, KnownResponseFormat, ResponseFormat, Schema } from '../types'5import type { StatusCode, SuccessStatusCode } from '../utils/http-status'6import type { HasRequiredKeys } from '../utils/types'78/**
346 unmodified lines
355 }356}357358export type ApplyGlobalResponse<App, Def extends GlobalResponseDefinition> =359 App extends HonoBase<infer E, infer D extends Schema, infer B>360 ? Hono<E, ModSchema<D, Def> extends Schema ? ModSchema<D, Def> : never, B>359 App extends HonoBase<infer E, infer _ extends Schema, infer B>360 ? ModSchema<ExtractSchema<App>, Def> extends infer S extends Schema361 ? Hono<E, S, B>362 : never363 : never