Skip to content

Commit

Permalink
fix(type): add child method default generic type
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusvellone committed May 3, 2023
1 parent c1c8eb4 commit 9322674
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pino.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ interface LoggerExtras<Options = LoggerOptions> extends EventEmitter {
* @param options: an options object that will override child logger inherited options.
* @returns a child logger instance.
*/
child<ChildOptions extends pino.ChildLoggerOptions>(bindings: pino.Bindings, options?: ChildOptions): pino.Logger<Options & ChildOptions>;
child<ChildOptions extends pino.ChildLoggerOptions = {}>(bindings: pino.Bindings, options?: ChildOptions): pino.Logger<Options & ChildOptions>;

/**
* This can be used to modify the callback function on creation of a new child.
Expand Down
12 changes: 12 additions & 0 deletions test/types/pino.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,15 @@ pino({
crlf: true,
});

const customLevels = { foo: 99 };

const customLevelLogger = pino({ customLevels });

type CustomLevelLogger = typeof customLevelLogger
type CustomLevelLoggerLevels = pino.Level | keyof typeof customLevels

const fn = (logger: Pick<CustomLevelLogger, CustomLevelLoggerLevels>) => {}

const customLevelChildLogger = customLevelLogger.child({ name: "child" })

fn(customLevelChildLogger); // missing foo typing

0 comments on commit 9322674

Please sign in to comment.