Skip to content
Myr

fix(client): Don't show `$ws` when not used WebSockets (#2532)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix(client): Don't show `$ws` when not used ws * test(client): add types test * chore: format code * chore: remove no used arg

authored by Shotaro Nakamura · committed by GitHub · parent 9f9a41c · Browse files · 5 files+39 added−16 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+39 added−16 removed

  • tests:+25 added−0 removed
  • other:+14 added−16 removed

5 files+39 added−16 removed

modified:deno_dist/client/types.ts+6 added-7 removed
modified:deno_dist/helper/websocket/index.ts+1 added-1 removed
added:src/client/types.test.ts+25 added
1import { expectTypeOf } from 'vitest'2import { Hono } from '..'3import { upgradeWebSocket } from '../helper'4import { hc } from '.'56describe('WebSockets', () => {7 const app = new Hono()8 .get(9 '/ws',10 upgradeWebSocket(() => ({}))11 )12 .get('/', (c) => c.json({}))13 const client = hc<typeof app>('/')1415 it('WebSocket route', () => {16 expectTypeOf(client.ws).toMatchTypeOf<{17 $ws: () => WebSocket18 }>()19 })20 it('Not WebSocket Route', () => {21 expectTypeOf<22 typeof client.index extends { $ws: () => WebSocket } ? false : true23 >().toEqualTypeOf(true)24 })25})
modified:src/client/types.ts+6 added-7 removed
31 unmodified lines
32 ? { param: P }33 : {}34 : {}35 ) => URL36} & {37 // WebSocket38 $ws: S['$get'] extends { input: { json: UpgradedWebSocketResponseInputJSONType } }36} & (S['$get'] extends { input: { json: UpgradedWebSocketResponseInputJSONType } }37 ? S['$get'] extends { input: infer I }40 ? (args?: Omit<I, 'json'>) => WebSocket41 : never42 : never43}38 ? {39 $ws: (args?: Omit<I, 'json'>) => WebSocket40 }41 : {}42 : {})4344// eslint-disable-next-line @typescript-eslint/no-explicit-any45type BlankRecordToNever<T> = T extends any46 ? T extends null
89 unmodified lines
modified:src/helper/websocket/index.ts+1 added-1 removed
10 unmodified lines
11 onClose?: (evt: CloseEvent, ws: WSContext) => void12 onError?: (evt: Event, ws: WSContext) => void13}1415export type UpgradedWebSocketResponseInputJSONType = '__websocket' | undefined15export type UpgradedWebSocketResponseInputJSONType = '__websocket'1617/**18 * Upgrade WebSocket Type19 */
36 unmodified lines