diff --git a/types/index.d.ts b/types/index.d.ts index ee84f36..b848454 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,15 +1,31 @@ /// import { + ContextConfigDefault, FastifyPluginCallback, FastifyRequest, + FastifySchema, preHandlerAsyncHookHandler, + RouteGenericInterface, RouteOptions } from 'fastify'; declare module 'fastify' { - interface FastifyInstance { - rateLimit: (options?: fastifyRateLimit.RateLimitOptions) => preHandlerAsyncHookHandler; + interface FastifyInstance { + rateLimit< + RouteGeneric extends RouteGenericInterface = RouteGenericInterface, + ContextConfig = ContextConfigDefault, + SchemaCompiler extends FastifySchema = FastifySchema, + >(options?: fastifyRateLimit.RateLimitOptions): preHandlerAsyncHookHandler< + RawServer, + RawRequest, + RawReply, + RouteGeneric, + ContextConfig, + SchemaCompiler, + TypeProvider, + Logger + >; } interface FastifyContextConfig { rateLimit?: fastifyRateLimit.RateLimitOptions | false; diff --git a/types/index.test-d.ts b/types/index.test-d.ts index e563af9..4c14c0a 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -7,6 +7,7 @@ import fastify, { } from 'fastify' import * as http2 from 'http2' import { default as ioredis } from 'ioredis' +import pino from 'pino'; import fastifyRateLimit, { errorResponseBuilderContext, FastifyRateLimitOptions, @@ -178,3 +179,16 @@ const errorResponseContext: errorResponseBuilderContext = { max: 1000, ttl: 123 } + +const appWithCustomLogger = fastify({ + loggerInstance: pino(), +}).withTypeProvider() + +appWithCustomLogger.register(fastifyRateLimit, options1) + +appWithCustomLogger.route({ + method: 'GET', + url: '/', + preHandler: appWithCustomLogger.rateLimit({}), + handler: () => {}, +})