-
-
Notifications
You must be signed in to change notification settings - Fork 546
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
v3.11.5 breaks typed routes on the client #1842
Comments
Thanks for raising the issue. To think about this more deeply, can you show me the minimal code to reproduce your problem? |
@yusukebe here's a link to a playground with a simple Hono app. Please note how |
It seems to me this is the issue with interfaces only. Plain types are transformed correctly. I think this remark from I'm not sure whether it is possible at all to make json transforms work with interfaces. |
How about using the export type JSONParsed<T> = T extends { toJSON(): infer J }
? (() => J) extends () => JSONObject
? J
: JSONParsed<J>
: T extends JSONPrimitive
? T
: T extends Array<infer U>
? Array<JSONParsed<U>>
: T extends object
? { [K in keyof T]: JSONParsed<T[K]> }
: never |
Seems to be working just fine. Thanks! |
What version of Hono are you using?
v3.11.9
What runtime/platform is your app running on?
Bun
What steps can reproduce the bug?
Link to TS Playground
What is the expected behavior?
Client should correctly transform the type of objects.
What do you see instead?
No response
Additional information
After an update to v3.11.9, the types for Hono client's responses in my app are now broken. The bug was introduced in v3.11.5 in PR #1806
Although transforming types to JSON works fine with simple objects, once you start using nested objects and interfaces, it falls apart.
The
Jsonify
utility from type-fest works fine, however. In the end of the playground I showed the correct types using this utility.I believe the fix should be easy to implement (i.e. just use the code from
type-fest
).The text was updated successfully, but these errors were encountered: