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

* fix(node-ws): allow `Hono` with custom Env

* add changeset
pull/953/head
Yusuke Wada 2025-02-02 21:25:54 +09:00 committed by GitHub
parent 5cad2e1afe
commit c80ffbfb4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 3 deletions

View File

@ -0,0 +1,5 @@
---
'@hono/node-ws': patch
---
fix: allow `Hono` with custom Env for `createNodeWebSocket`

View File

@ -9,7 +9,7 @@
"dist" "dist"
], ],
"scripts": { "scripts": {
"test": "vitest --run", "test": "tsc --noEmit && vitest --run",
"build": "tsup ./src/index.ts --format esm,cjs --dts", "build": "tsup ./src/index.ts --format esm,cjs --dts",
"publint": "publint", "publint": "publint",
"release": "yarn build && yarn test && yarn publint && yarn publish" "release": "yarn build && yarn test && yarn publint && yarn publish"

View File

@ -149,4 +149,15 @@ describe('WebSocket helper', () => {
expect((receivedMessage as Buffer).at(idx)).toBe(val) 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 })
})
})
}) })

View File

@ -12,7 +12,8 @@ export interface NodeWebSocket {
injectWebSocket(server: Server | Http2Server | Http2SecureServer): void injectWebSocket(server: Server | Http2Server | Http2SecureServer): void
} }
export interface NodeWebSocketInit { export interface NodeWebSocketInit {
app: Hono // eslint-disable-next-line @typescript-eslint/no-explicit-any
app: Hono<any, any, any>
baseUrl?: string | URL baseUrl?: string | URL
} }