Skip to content

Commit

Permalink
fix: generic type error of RouteShorthandMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
XHFkindergarten committed Dec 19, 2023
1 parent d1c6cec commit 024e70f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ declare module 'fastify' {
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
Logger extends FastifyBaseLogger = FastifyBaseLogger,
> {
<RequestGeneric extends RequestGenericInterface = RequestGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, Logger extends FastifyBaseLogger = FastifyBaseLogger>(
<RequestGeneric extends RequestGenericInterface = RequestGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, InnerLogger extends Logger = Logger>(
path: string,
opts: RouteShorthandOptions<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> & { websocket: true }, // this creates an overload that only applies these different types if the handler is for websockets
handler?: fastifyWebsocket.WebsocketHandler<RawServer, RawRequest, RequestGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
opts: RouteShorthandOptions<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig, SchemaCompiler, TypeProvider, InnerLogger> & { websocket: true }, // this creates an overload that only applies these different types if the handler is for websockets
handler?: fastifyWebsocket.WebsocketHandler<RawServer, RawRequest, RequestGeneric, ContextConfig, SchemaCompiler, TypeProvider, InnerLogger>
): FastifyInstance<RawServer, RawRequest, RawReply, InnerLogger, TypeProvider>;
}

interface RouteOptions<
Expand Down
1 change: 1 addition & 0 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ app.get('/websockets-via-inferrence', { websocket: true }, async function (conne
expectType<Server>(app.websocketServer);
expectType<FastifyRequest<RequestGenericInterface>>(request)
expectType<boolean>(request.ws);
expectType<FastifyBaseLogger>(request.log);
});

const handler: WebsocketHandler = async (connection, request) => {
Expand Down

0 comments on commit 024e70f

Please sign in to comment.