Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: type of child logger with custom levels #1871

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pino.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ declare namespace pino {
/**
* Optional child creation callback.
*/
onChild?: OnChildCallback;
onChild?: OnChildCallback<CustomLevels>;

/**
* logs newline delimited JSON with `\r\n` instead of `\n`. Default: `false`.
Expand Down Expand Up @@ -799,7 +799,7 @@ declare function pino<CustomLevels extends string = never>(optionsOrStream?: Log
* relative protocol is enabled. Default: process.stdout
* @returns a new logger instance.
*/
declare function pino<CustomLevels extends string>(options: LoggerOptions<CustomLevels>, stream: DestinationStream): Logger<CustomLevels>;
declare function pino<CustomLevels extends string = never>(options: LoggerOptions<CustomLevels>, stream: DestinationStream): Logger<CustomLevels>;


// Pass through all the top-level exports, allows `import {version} from "pino"`
Expand Down
20 changes: 20 additions & 0 deletions test/types/pino.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,23 @@ expectType<Logger<'log'>>(pino({
},
},
}))

const parentLogger1 = pino({
customLevels: { myLevel: 90 },
onChild: (child) => { const a = child.myLevel; }
}, process.stdout)
parentLogger1.onChild = (child) => { child.myLevel(''); }

const childLogger1 = parentLogger1.child({});
childLogger1.myLevel('');
expectError(childLogger1.doesntExist(''));

const parentLogger2 = pino({}, process.stdin);
expectError(parentLogger2.onChild = (child) => { const b = child.doesntExist; });

const childLogger2 = parentLogger2.child({});
expectError(childLogger2.doesntExist);

expectError(pino({
onChild: (child) => { const a = child.doesntExist; }
}, process.stdout));
Loading