Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"@fastify/type-provider-typebox": "^3.2.0",
"@types/node": "^20.1.0",
"@types/ws": "^8.2.2",
"fastify": "^4.16.0",
"fastify": "^4.25.0",
"fastify-tsconfig": "^2.0.0",
"split2": "^4.1.0",
"standard": "^17.0.0",
"tap": "^16.0.0",
Expand Down
4 changes: 2 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ declare module 'fastify' {
}

interface FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> {
get: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>,
get: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>,
websocketServer: WebSocket.Server,
}

Expand Down Expand Up @@ -108,4 +108,4 @@ declare namespace fastifyWebsocket {
}

declare function fastifyWebsocket(...params: Parameters<FastifyWebsocket>): ReturnType<FastifyWebsocket>
export = fastifyWebsocket
export = fastifyWebsocket
46 changes: 4 additions & 42 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import fastifyWebsocket, { WebsocketHandler, SocketStream, fastifyWebsocket as namedFastifyWebsocket, default as defaultFastifyWebsocket } from '..';
import type { IncomingMessage } from "http";
import fastify, { RouteOptions, FastifyRequest, FastifyInstance, FastifyReply, RequestGenericInterface, FastifyBaseLogger, RawServerDefault, FastifySchema, RawRequestDefaultExpression, RawServerBase, ContextConfigDefault, RawReplyDefaultExpression } from 'fastify';
import { expectAssignable, expectType } from 'tsd';
import fastify, { RouteOptions, FastifyRequest, FastifyInstance, FastifyReply, RequestGenericInterface, FastifyBaseLogger, RawServerDefault, FastifySchema, RawRequestDefaultExpression } from 'fastify';
import { expectType } from 'tsd';
import { Server } from 'ws';
import { RouteGenericInterface } from 'fastify/types/route';
import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox';
import { Static, Type } from '@sinclair/typebox'
import { ResolveFastifyRequestType } from 'fastify/types/type-provider';
import { Type } from '@sinclair/typebox'

const app: FastifyInstance = fastify();
app.register(fastifyWebsocket);
Expand Down Expand Up @@ -126,12 +125,6 @@ const schema = {
auth: Type.String()
})
};
type SchemaType = {
params: Static<typeof schema.params>;
querystring: Static<typeof schema.querystring>;
body: Static<typeof schema.body>;
headers: Static<typeof schema.headers>;
};

const server = app.withTypeProvider<TypeBoxTypeProvider>();

Expand All @@ -154,37 +147,6 @@ server.route({
},
});

// server.get('/websockets-type-inference',
// {
// websocket: true,
// schema
// },
// async function (connection, request) {
// expectType<FastifyInstance>(this);
// expectType<SocketStream>(connection);
// expectType<Server>(app.websocketServer);
// expectType<FastifyRequest<RequestGenericInterface, RawServerDefault, IncomingMessage, SchemaType, TypeBoxTypeProvider, unknown, FastifyBaseLogger>>(request);
// expectType<boolean>(request.ws);
// expectType<{ foo: string }>(request.params);
// expectType<{ bar: string }>(request.body);
// expectType<{ search: string }>(request.query);
// expectType<IncomingMessage['headers'] & { auth: string }>(request.headers);
// });

// server.get('/not-websockets-type-inference',
// {
// websocket: false,
// schema
// },
// async (request, reply) => {
// expectType<FastifyRequest<RouteGenericInterface, RawServerDefault, IncomingMessage, SchemaType, TypeBoxTypeProvider, unknown, FastifyBaseLogger, ResolveFastifyRequestType<TypeBoxTypeProvider, FastifySchema, RouteGenericInterface>>>(request);
// expectType<FastifyReply<RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, RouteGenericInterface, ContextConfigDefault, SchemaType, TypeBoxTypeProvider>>(reply);
// expectType<{ foo: string }>(request.params);
// expectType<{ bar: string }>(request.body);
// expectType<{ search: string }>(request.query);
// expectType<IncomingMessage['headers'] & { auth: string }>(request.headers);
// });

server.get('/websockets-no-type-inference',
{ websocket: true },
async function (connection, request) {
Expand All @@ -201,4 +163,4 @@ server.get('/websockets-no-type-inference',

expectType<typeof fastifyWebsocket>(namedFastifyWebsocket);
expectType<typeof fastifyWebsocket>(defaultFastifyWebsocket);