From 649f42f603fe199e1832a8f8769c3d3d7113859a Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Fri, 4 Oct 2024 14:54:27 +0530 Subject: [PATCH] Update types of fastify instance and plugin --- lib/build/framework/fastify/index.d.ts | 6 +++++- lib/build/framework/fastify/types.d.ts | 14 +++++++++++--- lib/ts/framework/fastify/types.ts | 14 +++++++++++--- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/build/framework/fastify/index.d.ts b/lib/build/framework/fastify/index.d.ts index b8cc44a0e..878d1ec23 100644 --- a/lib/build/framework/fastify/index.d.ts +++ b/lib/build/framework/fastify/index.d.ts @@ -1,6 +1,10 @@ // @ts-nocheck export type { SessionRequest } from "./framework"; -export declare const plugin: import("./types").FastifyPluginCallback; +export declare const plugin: import("./types").FastifyPluginCallback>; export declare const errorHandler: () => ( err: any, req: import("./types").FastifyRequest, diff --git a/lib/build/framework/fastify/types.d.ts b/lib/build/framework/fastify/types.d.ts index 7b73e61cf..86c117df5 100644 --- a/lib/build/framework/fastify/types.d.ts +++ b/lib/build/framework/fastify/types.d.ts @@ -19,7 +19,15 @@ export interface FastifyReply { getHeader(key: any): number | string | string[] | undefined; type(contentType: string): FastifyReply; } -export interface FastifyInstance { - addHook(name: string, hook: (req: Request, reply: Reply) => void): Instance; +export interface FastifyInstance< + Instance = unknown, + Request extends FastifyRequest = FastifyRequest, + Reply extends FastifyReply = FastifyReply +> { + addHook(this: Instance, name: string, hook: (req: Request, reply: Reply) => void): Instance; } -export declare type FastifyPluginCallback = (instance: any, opts: any, done: (err?: Error) => void) => void; +export declare type FastifyPluginCallback = ( + instance: Instance, + opts: unknown, + done: (err?: Error) => void +) => void; diff --git a/lib/ts/framework/fastify/types.ts b/lib/ts/framework/fastify/types.ts index ca965f97d..16d5a8b22 100644 --- a/lib/ts/framework/fastify/types.ts +++ b/lib/ts/framework/fastify/types.ts @@ -21,8 +21,16 @@ export interface FastifyReply { type(contentType: string): FastifyReply; } -export interface FastifyInstance { - addHook(name: string, hook: (req: Request, reply: Reply) => void): Instance; +export interface FastifyInstance< + Instance = unknown, + Request extends FastifyRequest = FastifyRequest, + Reply extends FastifyReply = FastifyReply +> { + addHook(this: Instance, name: string, hook: (req: Request, reply: Reply) => void): Instance; } -export type FastifyPluginCallback = (instance: any, opts: any, done: (err?: Error) => void) => void; +export type FastifyPluginCallback = ( + instance: Instance, + opts: unknown, + done: (err?: Error) => void +) => void;