diff --git a/pino.d.ts b/pino.d.ts index 8e7fe6ea9..e0f7466e7 100644 --- a/pino.d.ts +++ b/pino.d.ts @@ -600,7 +600,7 @@ declare namespace pino { * log method and method is the log method itself, and level is the log level. This hook must invoke the method function by * using apply, like so: method.apply(this, newArgumentsArray). */ - logMethod?: (args: any[], method: LogFn, level: number) => void; + logMethod?: (this: Logger, args: any[], method: LogFn, level: number) => void; }; /** diff --git a/test/types/pino.test-d.ts b/test/types/pino.test-d.ts index 57b8ca43c..e4ef8c885 100644 --- a/test/types/pino.test-d.ts +++ b/test/types/pino.test-d.ts @@ -1,7 +1,7 @@ import P, { pino } from "../../"; import { IncomingMessage, ServerResponse } from "http"; import { Socket } from "net"; -import { expectError } from 'tsd' +import { expectError, expectType } from 'tsd' import Logger = P.Logger; const log = pino(); @@ -229,6 +229,7 @@ const withNestedKey = pino({ const withHooks = pino({ hooks: { logMethod(args, method, level) { + expectType(this); return method.apply(this, ['msg', ...args]); }, }, @@ -344,4 +345,4 @@ cclog3.childLevel2('') const withChildCallback = pino({ onChild: (child: Logger) => {} }) -withChildCallback.onChild = (child: Logger) => {} \ No newline at end of file +withChildCallback.onChild = (child: Logger) => {}