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'
35import type { IncomingMessage } from 'node:http'
4- import fastify , { RouteOptions , FastifyRequest , FastifyInstance , FastifyReply , RequestGenericInterface , FastifyBaseLogger , RawServerDefault , FastifySchema , RawRequestDefaultExpression } from 'fastify'
56import { expectType } from 'tsd'
67import { 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 '..'
1010
1111const app : FastifyInstance = fastify ( )
1212app . register ( fastifyWebsocket )
@@ -22,8 +22,8 @@ app.register(fastifyWebsocket, {
2222 }
2323} )
2424app . 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 ( ) { } } )
2727
2828app . get ( '/websockets-via-inferrence' , { websocket : true } , async function ( socket , request ) {
2929 expectType < FastifyInstance > ( this )
@@ -89,7 +89,7 @@ app.get<{ Params: { foo: string }, Body: { bar: string }, Querystring: { search:
8989 expectType < { foo : string } > ( request . params )
9090 expectType < { bar : string } > ( request . body )
9191 expectType < { search : string } > ( request . query )
92- expectType < IncomingMessage [ 'headers' ] & { auth : string } > ( request . headers )
92+ expectType < IncomingMessage [ 'headers' ] & { auth : string } > ( request . headers )
9393} )
9494
9595app . route < { Params : { foo : string } , Body : { bar : string } , Querystring : { search : string } , Headers : { auth : string } } > ( {
@@ -162,3 +162,15 @@ server.get('/websockets-no-type-inference',
162162
163163expectType < typeof fastifyWebsocket > ( namedFastifyWebsocket )
164164expectType < 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