Skip to content

Hono RPC client - types inferred incorrectly #3485

@pjeziorowski

Description

@pjeziorowski

What version of Hono are you using?

4.6.2

What runtime/platform is your app running on?

Bun

What steps can reproduce the bug?

export type PreferencesDTO = {
  userId: string
  newMessages: boolean
  newConnectionRequests: boolean
  matchSuggestionsOrUpdates: boolean
  productUpdates: boolean
  createdAt: string
  updatedAt: string | null
}

const preferences: PreferencesDTO = {...}

return c.json({
  data: preferences
}, 200) ----> The "output" of this gets inferred as "any" in the client:

What is the expected behavior?

Types for the basic JS types are inferred correctly

What do you see instead?

Output type in the RPC client is of type any

image

Additional information

If you cast your output type like this

return c.json({
  data: preferences
}, 200) as {
        newMessages: boolean
        newConnectionRequests: boolean
        matchSuggestionsOrUpdates: boolean
        productUpdates: boolean
      } 

then it's fine, but it's super inconvenient to be forced to cast types like this

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions