diff --git a/deno_dist/client/types.ts b/deno_dist/client/types.ts index 31b039792..57e87aad6 100644 --- a/deno_dist/client/types.ts +++ b/deno_dist/client/types.ts @@ -43,7 +43,13 @@ export type ClientRequest = { } // eslint-disable-next-line @typescript-eslint/no-explicit-any -type BlankRecordToNever = T extends any ? (keyof T extends never ? never : T) : never +type BlankRecordToNever = T extends any + ? T extends null + ? null + : keyof T extends never + ? never + : T + : never export interface ClientResponse { readonly body: ReadableStream | null diff --git a/src/client/client.test.ts b/src/client/client.test.ts index c248d9d61..799f555a5 100644 --- a/src/client/client.test.ts +++ b/src/client/client.test.ts @@ -48,6 +48,7 @@ describe('Basic - JSON', () => { } ) .get('/hello-not-found', (c) => c.notFound()) + .get('/null', (c) => c.json(null)) type AppType = typeof route @@ -69,6 +70,9 @@ describe('Basic - JSON', () => { }), rest.get('http://localhost/hello-not-found', (_req, res, ctx) => { return res(ctx.status(404)) + }), + rest.get('http://localhost/null', (_req, res, ctx) => { + return res(ctx.status(200), ctx.json(null)) }) ) @@ -111,6 +115,14 @@ describe('Basic - JSON', () => { const res = await client['hello-not-found'].$get() expect(res.status).toBe(404) }) + + it('Should get a `null` content', async () => { + const client = hc('http://localhost') + const res = await client.null.$get() + const data = await res.json() + expectTypeOf(data).toMatchTypeOf() + expect(data).toBe(null) + }) }) describe('Basic - query, queries, form, path params, header and cookie', () => { diff --git a/src/client/types.ts b/src/client/types.ts index 1a3224a91..0bb1dbd84 100644 --- a/src/client/types.ts +++ b/src/client/types.ts @@ -43,7 +43,13 @@ export type ClientRequest = { } // eslint-disable-next-line @typescript-eslint/no-explicit-any -type BlankRecordToNever = T extends any ? (keyof T extends never ? never : T) : never +type BlankRecordToNever = T extends any + ? T extends null + ? null + : keyof T extends never + ? never + : T + : never export interface ClientResponse { readonly body: ReadableStream | null