11import fastifyWebsocket , { WebsocketHandler , SocketStream , fastifyWebsocket as namedFastifyWebsocket , default as defaultFastifyWebsocket } from '..' ;
22import type { IncomingMessage } from "http" ;
3- import fastify , { RouteOptions , FastifyRequest , FastifyInstance , FastifyReply , RequestGenericInterface , FastifyBaseLogger , RawServerDefault , FastifySchema , RawRequestDefaultExpression , RawServerBase , ContextConfigDefault , RawReplyDefaultExpression } from 'fastify' ;
4- import { expectAssignable , expectType } from 'tsd' ;
3+ import fastify , { RouteOptions , FastifyRequest , FastifyInstance , FastifyReply , RequestGenericInterface , FastifyBaseLogger , RawServerDefault , FastifySchema , RawRequestDefaultExpression } from 'fastify' ;
4+ import { expectType } from 'tsd' ;
55import { Server } from 'ws' ;
66import { RouteGenericInterface } from 'fastify/types/route' ;
77import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox' ;
8- import { Static , Type } from '@sinclair/typebox'
9- import { ResolveFastifyRequestType } from 'fastify/types/type-provider' ;
8+ import { Type } from '@sinclair/typebox'
109
1110const app : FastifyInstance = fastify ( ) ;
1211app . register ( fastifyWebsocket ) ;
@@ -126,12 +125,6 @@ const schema = {
126125 auth : Type . String ( )
127126 } )
128127} ;
129- type SchemaType = {
130- params : Static < typeof schema . params > ;
131- querystring : Static < typeof schema . querystring > ;
132- body : Static < typeof schema . body > ;
133- headers : Static < typeof schema . headers > ;
134- } ;
135128
136129const server = app . withTypeProvider < TypeBoxTypeProvider > ( ) ;
137130
@@ -154,37 +147,6 @@ server.route({
154147 } ,
155148} ) ;
156149
157- // server.get('/websockets-type-inference',
158- // {
159- // websocket: true,
160- // schema
161- // },
162- // async function (connection, request) {
163- // expectType<FastifyInstance>(this);
164- // expectType<SocketStream>(connection);
165- // expectType<Server>(app.websocketServer);
166- // expectType<FastifyRequest<RequestGenericInterface, RawServerDefault, IncomingMessage, SchemaType, TypeBoxTypeProvider, unknown, FastifyBaseLogger>>(request);
167- // expectType<boolean>(request.ws);
168- // expectType<{ foo: string }>(request.params);
169- // expectType<{ bar: string }>(request.body);
170- // expectType<{ search: string }>(request.query);
171- // expectType<IncomingMessage['headers'] & { auth: string }>(request.headers);
172- // });
173-
174- // server.get('/not-websockets-type-inference',
175- // {
176- // websocket: false,
177- // schema
178- // },
179- // async (request, reply) => {
180- // expectType<FastifyRequest<RouteGenericInterface, RawServerDefault, IncomingMessage, SchemaType, TypeBoxTypeProvider, unknown, FastifyBaseLogger, ResolveFastifyRequestType<TypeBoxTypeProvider, FastifySchema, RouteGenericInterface>>>(request);
181- // expectType<FastifyReply<RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, RouteGenericInterface, ContextConfigDefault, SchemaType, TypeBoxTypeProvider>>(reply);
182- // expectType<{ foo: string }>(request.params);
183- // expectType<{ bar: string }>(request.body);
184- // expectType<{ search: string }>(request.query);
185- // expectType<IncomingMessage['headers'] & { auth: string }>(request.headers);
186- // });
187-
188150server . get ( '/websockets-no-type-inference' ,
189151 { websocket : true } ,
190152 async function ( connection , request ) {
@@ -201,4 +163,4 @@ server.get('/websockets-no-type-inference',
201163
202164 expectType < typeof fastifyWebsocket > ( namedFastifyWebsocket ) ;
203165 expectType < typeof fastifyWebsocket > ( defaultFastifyWebsocket ) ;
204-
166+
0 commit comments