Skip to content
Myr

fix(client): make `ClientResponse.json()` returns Union correctly (#1786)

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

* fix(client): make `ClientResponse.json()` returns Union correctly * denoify

authored by Yusuke Wada · committed by GitHub · parent 1906010 · Browse files · 3 files+22 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+22 added−2 removed

  • tests:+18 added−0 removed
  • other:+4 added−2 removed

3 files+22 added−2 removed

modified:deno_dist/client/types.ts+2 added-1 removed
modified:src/client/client.test.ts+18 added
586 unmodified lines
587 message?: string588 }>()589 })590})591592describe('ClientResponse<T>.json() returns a Union type correctly', () => {593 const condition = () => true594 const app = new Hono().get('/', async (c) => {595 const ok = condition()596 if (ok) {597 return c.json({ data: 'foo' })598 }599 return c.json({ message: 'error' })600 })601602 const client = hc<typeof app>('', { fetch: app.request })603 it('Should be a Union type', async () => {604 const res = await client.index.$get()605 const json = await res.json()606 expectTypeOf(json).toEqualTypeOf<{ data: string } | { message: string }>()607 })608})
modified:src/client/types.ts+2 added-1 removed
24 unmodified lines
25} & {26 $url: () => URL27}2829type BlankRecordToNever<T> = keyof T extends never ? never : T29// eslint-disable-next-line @typescript-eslint/no-explicit-any30type BlankRecordToNever<T> = T extends any ? (keyof T extends never ? never : T) : never3132export interface ClientResponse<T> {33 ok: boolean34 status: number
78 unmodified lines