Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#49933 [pino-http] fix: Declare support for…
Browse files Browse the repository at this point in the history
… the optional `next` parameter by @kf6kjg

The actual code handles it just fine, it looks like it was a simple omission.

With this in place, as my locally patched edition has it, I can use AsyncLocalStorage to keep the logger context across the whole request.
  • Loading branch information
kf6kjg authored Dec 6, 2020
1 parent 2540e79 commit 6db3bda
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion types/pino-http/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ declare function PinoHttp(opts?: PinoHttp.Options, stream?: DestinationStream):
declare function PinoHttp(stream?: DestinationStream): PinoHttp.HttpLogger;

declare namespace PinoHttp {
type HttpLogger = (req: IncomingMessage, res: ServerResponse) => void;
type HttpLogger = (req: IncomingMessage, res: ServerResponse, next?: () => void) => void;
type ReqId = number | string | object;

/**
Expand Down
7 changes: 7 additions & 0 deletions types/pino-http/pino-http-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ function handle(req: http.IncomingMessage, res: http.ServerResponse) {
res[pinoHttp.startTime] = Date.now();
}

function handle_with_next(req: http.IncomingMessage, res: http.ServerResponse, next: () => void) {
pinoHttp()(req, res, () => {
// Do a thing.
next();
});
}

pinoHttp({ logger });
pinoHttp({ genReqId: req => req.statusCode || 200 });
pinoHttp({ genReqId: req => 'foo' });
Expand Down

0 comments on commit 6db3bda

Please sign in to comment.