Skip to content

Commit 9e5e8f1

Browse files
authored
Fix types compatibility with Fastify v4.25.0 (#278)
Signed-off-by: Matteo Collina <hello@matteocollina.com>
1 parent ba185e8 commit 9e5e8f1

File tree

3 files changed

+8
-45
lines changed

3 files changed

+8
-45
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"@fastify/type-provider-typebox": "^3.2.0",
3131
"@types/node": "^20.1.0",
3232
"@types/ws": "^8.2.2",
33-
"fastify": "^4.16.0",
33+
"fastify": "^4.25.0",
34+
"fastify-tsconfig": "^2.0.0",
3435
"split2": "^4.1.0",
3536
"standard": "^17.0.0",
3637
"tap": "^16.0.0",

types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ declare module 'fastify' {
2828
}
2929

3030
interface FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> {
31-
get: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>,
31+
get: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>,
3232
websocketServer: WebSocket.Server,
3333
}
3434

@@ -108,4 +108,4 @@ declare namespace fastifyWebsocket {
108108
}
109109

110110
declare function fastifyWebsocket(...params: Parameters<FastifyWebsocket>): ReturnType<FastifyWebsocket>
111-
export = fastifyWebsocket
111+
export = fastifyWebsocket

types/index.test-d.ts

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import fastifyWebsocket, { WebsocketHandler, SocketStream, fastifyWebsocket as namedFastifyWebsocket, default as defaultFastifyWebsocket } from '..';
22
import 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';
55
import { Server } from 'ws';
66
import { RouteGenericInterface } from 'fastify/types/route';
77
import { 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

1110
const app: FastifyInstance = fastify();
1211
app.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

136129
const 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-
188150
server.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

Comments
 (0)