Skip to content

Commit

Permalink
fix: type default value
Browse files Browse the repository at this point in the history
  • Loading branch information
Agostino Cavarero committed Nov 1, 2023
1 parent 5203324 commit 5e2539b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pino.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type TimeFn = () => string;
type MixinFn = (mergeObject: object, level: number) => object;
type MixinMergeStrategyFn = (mergeObject: object, mixinObject: object) => object;

type CustomLevelLogger<CustomLevels> = CustomLevels extends Record<string, number> ? Record<keyof CustomLevels, LogFn> : Record<never, LogFn>
type CustomLevelLogger<CustomLevels extends Record<string, number>> = Record<keyof CustomLevels, LogFn>

/**
* A synchronous callback that will run on each creation of a new child.
Expand Down Expand Up @@ -80,7 +80,7 @@ export interface LoggerExtras<CustomLevels extends Record<string, number> = {}>
* @param options: an options object that will override child logger inherited options.
* @returns a child logger instance.
*/
child<ChildCustomLevels extends Record<string, number>>(bindings: pino.Bindings, options?: ChildLoggerOptions<ChildCustomLevels>): pino.Logger<CustomLevels & ChildCustomLevels>;
child<ChildCustomLevels extends Record<string, number> = {}>(bindings: pino.Bindings, options?: ChildLoggerOptions<ChildCustomLevels>): pino.Logger<CustomLevels & ChildCustomLevels>;

/**
* This can be used to modify the callback function on creation of a new child.
Expand Down
5 changes: 4 additions & 1 deletion test/types/pino.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ cclog3.childLevel('')
// child itself
cclog3.childLevel2('')

const ccclog3 = clog3.child({})
expectError(ccclog3.nonLevel(''))

const withChildCallback = pino({
onChild: (child: Logger) => {}
})
Expand All @@ -341,7 +344,7 @@ const fn = (logger: Pick<CustomLevelLogger, CustomLevelLoggerLevels>) => {}

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

expectError(fn(customLevelChildLogger)); // missing foo typing
fn(customLevelChildLogger); // missing foo typing

// unknown option
expectError(
Expand Down

0 comments on commit 5e2539b

Please sign in to comment.