-
-
Notifications
You must be signed in to change notification settings - Fork 634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type 'ClientResponse<T, U, F>' is not assignable to type 'void | Response'. #3750
Comments
@EdamAme-x |
Hi @satoshun00 This is not a bug with unexpected behavior; the type of the response used in the RPC client and the type of the response returned in the handler are different. |
@yusukebe |
The difference between the Response type in const response = new Response()
const data = await response.json<{ foo: string }>() So, we can prevent the error by changing the definition of diff --git a/src/client/types.ts b/src/client/types.ts
index 29e5790e..62235cad 100644
--- a/src/client/types.ts
+++ b/src/client/types.ts
@@ -89,11 +89,13 @@ export interface ClientResponse<
url: string
redirect(url: string, status: number): Response
clone(): Response
- json(): F extends 'text'
+ json<JSONT>(): F extends 'text'
? Promise<never>
: F extends 'json'
- ? Promise<BlankRecordToNever<T>>
- : Promise<unknown>
+ ? undefined extends JSONT
+ ? Promise<BlankRecordToNever<T>>
+ : JSONT
+ : Promise<JSONT>
text(): F extends 'text' ? (T extends string ? Promise<T> : Promise<never>) : Promise<string>
blob(): Promise<Blob> |
When creating a Workers application that bypasses access to a specific Hono application, the fix would make me very happy as it eliminates the need for extra type casting. However, my concern would be that it might introduce unnecessary looseness in the |
This issue has been marked as stale due to inactivity. |
I'll label this as an enhancement. |
It seems that a type mismatch still occurs even after applying the patch provided by @yusukebe.
I couldn't come up with a solution for resolving the issue by modifying the For now, in my project, I have implemented a temporary workaround by overriding the return type of declare interface Response extends globalThis.Response {
readonly json(): Promise<unknown>;
} |
What version of Hono are you using?
4.6.13
What runtime/platform is your app running on? (with version if possible)
Cloudflare Workers
What steps can reproduce the bug?
reproduction: https://github.com/satoshun00/hono-client-response-repro
What is the expected behavior?
It should be possible to return the response (
ClientResponse
) from hono/client as the response (globalThis.Response
) of the handler.What do you see instead?
TypeScript Error
Additional information
The text was updated successfully, but these errors were encountered: