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 6eb25d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 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
8 changes: 6 additions & 2 deletions test/types/pino.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ pino({
});

pino({ base: null });
if ("pino" in log) console.log(`pino version: `);
// @ts-expect-error
if ("pino" in log) console.log(`pino version: ${log.pino}`);

expectType<void>(log.flush());
log.flush((err?: Error) => undefined);
Expand Down Expand Up @@ -321,6 +322,9 @@ cclog3.childLevel('')
// child itself
cclog3.childLevel2('')

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

const withChildCallback = pino({
onChild: (child: Logger) => {}
})
Expand All @@ -341,7 +345,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 6eb25d8

Please sign in to comment.