diff --git a/pino.d.ts b/pino.d.ts index fb6337783..aedce4239 100644 --- a/pino.d.ts +++ b/pino.d.ts @@ -630,7 +630,7 @@ declare namespace pino { /** * Optional child creation callback. */ - onChild?: OnChildCallback; + onChild?: OnChildCallback; /** * logs newline delimited JSON with `\r\n` instead of `\n`. Default: `false`. @@ -799,7 +799,7 @@ declare function pino(optionsOrStream?: Log * relative protocol is enabled. Default: process.stdout * @returns a new logger instance. */ -declare function pino(options: LoggerOptions, stream: DestinationStream): Logger; +declare function pino(options: LoggerOptions, stream: DestinationStream): Logger; // Pass through all the top-level exports, allows `import {version} from "pino"` diff --git a/test/types/pino.test-d.ts b/test/types/pino.test-d.ts index 81ad9af09..ee78e3d34 100644 --- a/test/types/pino.test-d.ts +++ b/test/types/pino.test-d.ts @@ -404,3 +404,23 @@ expectType>(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));