Skip to content
Myr

fix(client): infer `null` correctly (#2469)

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

* fix(client): infer `null` correctly * denoify

authored by Yusuke Wada · committed by GitHub · parent 35f15b7 · Browse files · 3 files+26 added−2 removed
This commit

State

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

Diff stats

3 files+26 added−2 removed

  • tests:+12 added−0 removed
  • other:+14 added−2 removed

3 files+26 added−2 removed

modified:deno_dist/client/types.ts+7 added-1 removed
modified:src/client/client.test.ts+12 added
46 unmodified lines
47 })48 }49 )50 .get('/hello-not-found', (c) => c.notFound())51 .get('/null', (c) => c.json(null))5253 type AppType = typeof route5455 const server = setupServer(
13 unmodified lines
69 return res(ctx.status(200), ctx.json(payload))70 }),71 rest.get('http://localhost/hello-not-found', (_req, res, ctx) => {72 return res(ctx.status(404))73 }),74 rest.get('http://localhost/null', (_req, res, ctx) => {75 return res(ctx.status(200), ctx.json(null))76 })77 )7879 beforeAll(() => server.listen())
34 unmodified lines
114 it('Should get 404 response', async () => {115 const res = await client['hello-not-found'].$get()116 expect(res.status).toBe(404)117 })118119 it('Should get a `null` content', async () => {120 const client = hc<AppType>('http://localhost')121 const res = await client.null.$get()122 const data = await res.json()123 expectTypeOf(data).toMatchTypeOf<null>()124 expect(data).toBe(null)125 })126})127128describe('Basic - query, queries, form, path params, header and cookie', () => {129 const app = new Hono()
559 unmodified lines
modified:src/client/types.ts+7 added-1 removed
41 unmodified lines
42 : never43}4445// eslint-disable-next-line @typescript-eslint/no-explicit-any46type BlankRecordToNever<T> = T extends any ? (keyof T extends never ? never : T) : never46type BlankRecordToNever<T> = T extends any47 ? T extends null48 ? null49 : keyof T extends never50 ? never51 : T52 : never5354export interface ClientResponse<T> {55 readonly body: ReadableStream | null56 readonly bodyUsed: boolean
80 unmodified lines