Skip to content

Commit

Permalink
fix: TypeScript for CustomLevels on parent pino instance (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffreyEmerson authored Dec 27, 2023
1 parent 01134b9 commit 3f605c6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
6 changes: 3 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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, CustomLevels extends string = never>(opts?: Options<IM, SR>, stream?: pino.DestinationStream): HttpLogger<IM, SR, CustomLevels>;
declare function PinoHttp<IM = IncomingMessage, SR = ServerResponse, CustomLevels extends string = never>(opts?: Options<IM, SR, CustomLevels>, stream?: pino.DestinationStream): HttpLogger<IM, SR, CustomLevels>;

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

Expand All @@ -22,8 +22,8 @@ export interface HttpLogger<IM = IncomingMessage, SR = ServerResponse, CustomLev
}
export type ReqId = number | string | object;

export interface Options<IM = IncomingMessage, SR = ServerResponse> extends pino.LoggerOptions {
logger?: pino.Logger | undefined;
export interface Options<IM = IncomingMessage, SR = ServerResponse, CustomLevels extends string = never> extends pino.LoggerOptions {
logger?: pino.Logger<CustomLevels> | undefined;
genReqId?: GenReqId<IM, SR> | undefined;
useLevel?: pino.LevelWithSilent | undefined;
stream?: pino.DestinationStream | undefined;
Expand Down
11 changes: 11 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,14 @@ pinoHttp<IncomingMessage, ServerResponse, 'bark'>({
bark: 25,
}
}).logger.bark("arf arf");

// customLevels in parent pino instance should be not cause
// TypeScript errors
const customLogger = pino({
customLevels: {
bark: 25,
}
});
pinoHttp({
logger: customLogger
}).logger.bark("arf arf");
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"types": "index.d.ts",
"dependencies": {
"get-caller-file": "^2.0.5",
"pino": "^8.17.0",
"pino-std-serializers": "^6.0.0",
"pino": "^8.17.1",
"pino-std-serializers": "^6.2.2",
"process-warning": "^3.0.0"
},
"devDependencies": {
Expand Down

0 comments on commit 3f605c6

Please sign in to comment.