Skip to content

Commit

Permalink
fix: Pino options have a generic type
Browse files Browse the repository at this point in the history
  • Loading branch information
UndefinedBehaviour authored and Agostino Cavarero committed Oct 24, 2023
1 parent 9bf0802 commit 467bb96
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import { IncomingMessage, ServerResponse } from 'http';
import pino from 'pino';
import { err, req, res, SerializedError, SerializedRequest, SerializedResponse } from 'pino-std-serializers';

declare function PinoHttp<IM = IncomingMessage, SR = ServerResponse>(opts?: Options<IM, SR>, stream?: pino.DestinationStream): HttpLogger<IM, SR>;
declare function PinoHttp<IM = IncomingMessage, SR = ServerResponse, Opts = Options<IM, SR>>(opts?: Opts, stream?: pino.DestinationStream): HttpLogger<IM, SR, Opts>;

declare function PinoHttp<IM = IncomingMessage, SR = ServerResponse>(stream?: pino.DestinationStream): HttpLogger<IM, SR>;

export interface HttpLogger<IM = IncomingMessage, SR = ServerResponse> {
export interface HttpLogger<IM = IncomingMessage, SR = ServerResponse, Opts = Options<IM, SR>> {
(req: IM, res: SR, next?: () => void): void;
logger: pino.Logger;
logger: pino.Logger<Opts>;
}
export type ReqId = number | string | object;

Expand Down
10 changes: 10 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,13 @@ const httpServerListener: RequestListener = (request, response) => {
request.allLogs[0].info("allLogs available on response");
response.end("Hello world");
};

// custom levels added in the options should be available
// on the logger returned by pino-http
pinoHttp({
customLevels: {
bark: 25,
z: 90
},
fhfh: true
}).logger.bark("arf arf");

0 comments on commit 467bb96

Please sign in to comment.