Skip to content

Commit 03e7d0a

Browse files
committed
feat: improve UpgradeWebSocket types flow
1 parent a4f88b8 commit 03e7d0a

File tree

4 files changed

+6
-16
lines changed

4 files changed

+6
-16
lines changed

deno_dist/client/types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { UpgradedWebSocketResponseInputJSONType } from '../helper/websocket/index.ts'
21
import type { Hono } from '../hono.ts'
32
import type { Endpoint, ResponseFormat, Schema } from '../types.ts'
43
import type { StatusCode, SuccessStatusCode } from '../utils/http-status.ts'
@@ -34,10 +33,10 @@ export type ClientRequest<S extends Schema> = {
3433
: {}
3534
: {}
3635
) => URL
37-
} & (S['$get'] extends { input: { json: UpgradedWebSocketResponseInputJSONType } }
36+
} & (S['$get'] extends { outputFormat: 'ws' }
3837
? S['$get'] extends { input: infer I }
3938
? {
40-
$ws: (args?: Omit<I, 'json'>) => WebSocket
39+
$ws: (args?: I) => WebSocket
4140
}
4241
: {}
4342
: {})

deno_dist/helper/websocket/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ export interface WSEvents {
1212
onError?: (evt: Event, ws: WSContext) => void
1313
}
1414

15-
export type UpgradedWebSocketResponseInputJSONType = '__websocket'
16-
1715
/**
1816
* Upgrade WebSocket Type
1917
*/
@@ -23,9 +21,7 @@ export type UpgradeWebSocket = (
2321
any,
2422
string,
2523
{
26-
in: {
27-
json: UpgradedWebSocketResponseInputJSONType
28-
}
24+
outputFormat: 'ws'
2925
}
3026
>
3127

src/client/types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { UpgradedWebSocketResponseInputJSONType } from '../helper/websocket'
21
import type { Hono } from '../hono'
32
import type { Endpoint, ResponseFormat, Schema } from '../types'
43
import type { StatusCode, SuccessStatusCode } from '../utils/http-status'
@@ -34,10 +33,10 @@ export type ClientRequest<S extends Schema> = {
3433
: {}
3534
: {}
3635
) => URL
37-
} & (S['$get'] extends { input: { json: UpgradedWebSocketResponseInputJSONType } }
36+
} & (S['$get'] extends { outputFormat: 'ws' }
3837
? S['$get'] extends { input: infer I }
3938
? {
40-
$ws: (args?: Omit<I, 'json'>) => WebSocket
39+
$ws: (args?: I) => WebSocket
4140
}
4241
: {}
4342
: {})

src/helper/websocket/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ export interface WSEvents {
1212
onError?: (evt: Event, ws: WSContext) => void
1313
}
1414

15-
export type UpgradedWebSocketResponseInputJSONType = '__websocket'
16-
1715
/**
1816
* Upgrade WebSocket Type
1917
*/
@@ -23,9 +21,7 @@ export type UpgradeWebSocket = (
2321
any,
2422
string,
2523
{
26-
in: {
27-
json: UpgradedWebSocketResponseInputJSONType
28-
}
24+
outputFormat: 'ws'
2925
}
3026
>
3127

0 commit comments

Comments
 (0)