Skip to content

Commit

Permalink
fix: type variable for Logger
Browse files Browse the repository at this point in the history
the type variable of the logger should be the custom levels type
since a recent change in pino types (#304)

fixes #313
  • Loading branch information
naseemkullah committed Dec 15, 2023
1 parent 44c61b7 commit 130927e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 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>>(opts?: Opts, stream?: pino.DestinationStream): HttpLogger<IM, SR, Opts>;
declare function PinoHttp<IM = IncomingMessage, SR = ServerResponse, CL extends string = never>(opts?: Options<IM, SR>, stream?: pino.DestinationStream): HttpLogger<IM, SR, CL>;

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

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

Expand Down
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const httpServerListener: RequestListener = (request, response) => {

// custom levels added in the options should be available
// on the logger returned by pino-http
pinoHttp({
pinoHttp<IncomingMessage, ServerResponse, 'bark'>({
customLevels: {
bark: 25,
}
Expand Down

0 comments on commit 130927e

Please sign in to comment.