We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Currently, context variables can be defined in normal (non-WebSocket) routes like this:
type ContextVariables = { foo: number; } const app = new Hono<{ Variables: ContextVariables }>(); app.get('/', (c) => { const foo = c.var.foo; // number ... })
But, when using upgradeWebSocket from hono/bun, the types don't work:
upgradeWebSocket
hono/bun
import { createBunWebSocket } from 'hono/bun' import type { ServerWebSocket } from 'bun' const { upgradeWebSocket, websocket } = createBunWebSocket<ServerWebSocket>() type ContextVariables = { foo: number; } const app = new Hono<{ Variables: ContextVariables }>() app.get( '/ws', upgradeWebSocket((c) => { const foo = c.var.foo; // any ... }) )
Globally extending ContextVariableMap is problematic when the app has multiple routes where every route has its own context fields:
ContextVariableMap
declare module 'hono' { interface ContextVariableMap { foo: number; } }
It would be nice to have the ability to specify context variables per WebSocket route, e.g.:
app.get( '/ws1', upgradeWebSocket<{ Variables: { foo: number, bar: boolean } }>((c) => { const foo = c.var.foo; // number const bar = c.var.bar; // boolean ... }) ) app.get( '/ws2', upgradeWebSocket<{ Variables: { foo: string } }>((c) => { const foo = c.var.foo; // string const bar = c.var.bar; // Property 'bar' does not exist... ... }) )
The text was updated successfully, but these errors were encountered:
Thanks!
This is related to #3202
Sorry, something went wrong.
No branches or pull requests
What is the feature you are proposing?
Currently, context variables can be defined in normal (non-WebSocket) routes like this:
But, when using
upgradeWebSocket
fromhono/bun
, the types don't work:Globally extending
ContextVariableMap
is problematic when the app has multiple routes where every route has its own context fields:It would be nice to have the ability to specify context variables per WebSocket route, e.g.:
The text was updated successfully, but these errors were encountered: