Skip to content
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

fix(node-ws): allow Hono with custom Env for createNodeWebSocket #951

Merged
merged 2 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ninety-dogs-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hono/node-ws': patch
---

fix: allow `Hono` with custom Env for `createNodeWebSocket`
4 changes: 2 additions & 2 deletions packages/node-ws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dist"
],
"scripts": {
"test": "vitest --run",
"test": "tsc --noEmit && vitest --run",
"build": "tsup ./src/index.ts --format esm,cjs --dts",
"publint": "publint",
"release": "yarn build && yarn test && yarn publint && yarn publish"
Expand Down Expand Up @@ -48,4 +48,4 @@
"engines": {
"node": ">=18.14.1"
}
}
}
11 changes: 11 additions & 0 deletions packages/node-ws/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,15 @@ describe('WebSocket helper', () => {
expect((receivedMessage as Buffer).at(idx)).toBe(val)
})
})

describe('Types', () => {
it('Should not throw a type error with an app with Variables generics', () => {
const app = new Hono<{
Variables: {
foo: string
}
}>()
createNodeWebSocket({ app })
})
})
})
3 changes: 2 additions & 1 deletion packages/node-ws/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export interface NodeWebSocket {
injectWebSocket(server: Server | Http2Server | Http2SecureServer): void
}
export interface NodeWebSocketInit {
app: Hono
// eslint-disable-next-line @typescript-eslint/no-explicit-any
app: Hono<any, any, any>
baseUrl?: string | URL
}

Expand Down