1
- // eslint-disable-next-line import-x/no-named-default -- Testing default export
2
- import fastifyWebsocket , { WebsocketHandler , fastifyWebsocket as namedFastifyWebsocket , default as defaultFastifyWebsocket , WebSocket } from '..'
1
+ import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox'
2
+ import { Type } from '@sinclair/typebox'
3
+ import fastify , { FastifyBaseLogger , FastifyInstance , FastifyReply , FastifyRequest , FastifySchema , RawRequestDefaultExpression , RawServerDefault , RequestGenericInterface , RouteOptions } from 'fastify'
4
+ import { RouteGenericInterface } from 'fastify/types/route'
3
5
import type { IncomingMessage } from 'node:http'
4
- import fastify , { RouteOptions , FastifyRequest , FastifyInstance , FastifyReply , RequestGenericInterface , FastifyBaseLogger , RawServerDefault , FastifySchema , RawRequestDefaultExpression } from 'fastify'
5
6
import { expectType } from 'tsd'
6
7
import { Server } from 'ws'
7
- import { RouteGenericInterface } from 'fastify/types/route'
8
- import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox'
9
- import { Type } from '@sinclair/typebox'
8
+ // eslint-disable-next-line import-x/no-named-default -- Test default export
9
+ import fastifyWebsocket , { default as defaultFastifyWebsocket , fastifyWebsocket as namedFastifyWebsocket , WebSocket , WebsocketHandler } from '..'
10
10
11
11
const app : FastifyInstance = fastify ( )
12
12
app . register ( fastifyWebsocket )
@@ -22,8 +22,8 @@ app.register(fastifyWebsocket, {
22
22
}
23
23
} )
24
24
app . register ( fastifyWebsocket , { options : { perMessageDeflate : true } } )
25
- app . register ( fastifyWebsocket , { preClose : function syncPreclose ( ) { } } )
26
- app . register ( fastifyWebsocket , { preClose : async function asyncPreclose ( ) { } } )
25
+ app . register ( fastifyWebsocket , { preClose : function syncPreclose ( ) { } } )
26
+ app . register ( fastifyWebsocket , { preClose : async function asyncPreclose ( ) { } } )
27
27
28
28
app . get ( '/websockets-via-inferrence' , { websocket : true } , async function ( socket , request ) {
29
29
expectType < FastifyInstance > ( this )
@@ -89,7 +89,7 @@ app.get<{ Params: { foo: string }, Body: { bar: string }, Querystring: { search:
89
89
expectType < { foo : string } > ( request . params )
90
90
expectType < { bar : string } > ( request . body )
91
91
expectType < { search : string } > ( request . query )
92
- expectType < IncomingMessage [ 'headers' ] & { auth : string } > ( request . headers )
92
+ expectType < IncomingMessage [ 'headers' ] & { auth : string } > ( request . headers )
93
93
} )
94
94
95
95
app . route < { Params : { foo : string } , Body : { bar : string } , Querystring : { search : string } , Headers : { auth : string } } > ( {
@@ -162,3 +162,15 @@ server.get('/websockets-no-type-inference',
162
162
163
163
expectType < typeof fastifyWebsocket > ( namedFastifyWebsocket )
164
164
expectType < typeof fastifyWebsocket > ( defaultFastifyWebsocket )
165
+
166
+ app . injectWS ( '/' , { } , { } )
167
+ app . injectWS ( '/' , { } , {
168
+ onInit ( ws ) {
169
+ expectType < WebSocket > ( ws )
170
+ } ,
171
+ } )
172
+ app . injectWS ( '/' , { } , {
173
+ onOpen ( ws ) {
174
+ expectType < WebSocket > ( ws )
175
+ } ,
176
+ } )
0 commit comments