Skip to content

Commit a769539

Browse files
authoredSep 16, 2022
fix: add this to hooks.logMethod (#1559)
1 parent 44fe7d1 commit a769539

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed
 

‎pino.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ declare namespace pino {
600600
* log method and method is the log method itself, and level is the log level. This hook must invoke the method function by
601601
* using apply, like so: method.apply(this, newArgumentsArray).
602602
*/
603-
logMethod?: (args: any[], method: LogFn, level: number) => void;
603+
logMethod?: (this: Logger, args: any[], method: LogFn, level: number) => void;
604604
};
605605

606606
/**

‎test/types/pino.test-d.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import P, { pino } from "../../";
22
import { IncomingMessage, ServerResponse } from "http";
33
import { Socket } from "net";
4-
import { expectError } from 'tsd'
4+
import { expectError, expectType } from 'tsd'
55
import Logger = P.Logger;
66

77
const log = pino();
@@ -229,6 +229,7 @@ const withNestedKey = pino({
229229
const withHooks = pino({
230230
hooks: {
231231
logMethod(args, method, level) {
232+
expectType<pino.Logger>(this);
232233
return method.apply(this, ['msg', ...args]);
233234
},
234235
},
@@ -344,4 +345,4 @@ cclog3.childLevel2('')
344345
const withChildCallback = pino({
345346
onChild: (child: Logger) => {}
346347
})
347-
withChildCallback.onChild = (child: Logger) => {}
348+
withChildCallback.onChild = (child: Logger) => {}

0 commit comments

Comments
 (0)
Please sign in to comment.