Generic Types Not Working as Expected
I'm facing an issue with generic types in a
Any ideas or workarounds would be greatly appreciated! 🙏
---
PaginatedResponse
setup. Here's my use case:
Code Example:
The Problem:
The client-side response lacks type safety. Even though the generic type PaginatedResponse<BookingWithRelations>
is correctly defined, the returned response doesn't enforce or reflect the expected type safety.
I'm unsure if this is due to a limitation in the type inference, serialization, or something else entirely.
---
Question:
How can I ensure type safety is preserved in the client for such scenarios?Any ideas or workarounds would be greatly appreciated! 🙏
---
2 Replies
there are a few patterns that can break hono client type inference, namely:
- abstracting controller logic without using
createFactory
- defining method handlers as independent statements (rather than chaining)
for more info, check out the best practices docs: https://hono.dev/docs/guides/best-practicesBest Practices - Hono
Web framework built on Web Standards for Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, Node.js, and others. Fast, but not only fast.
it's hard to say more without knowing how you've set up your backend