pino
pino copied to clipboard
pino.LoggerOptions.level type is incorrect
Pino exports types for most of its components, however, I have noticed that the optional values in the pino.LoggerOptions do not produce 100% type correctness. As an example:
// Throws: Error: default level:undefined must be included in custom levels
const logger = pino({ nestedKey: "data", level: undefined }, lTransport);
This code will compile but pino will complain about a type error. I believe this is due to the fact the object now has a declared property "level" that can be enumerated over. I don't know of a way to say "you cannot pass an object with properties set to undefined" in typescript.
Fixing this for TypeScript users will probably require a bit of a change/refactor of the way config is handled.
cc @kibertoad
If you need TypeScript to distinguish the different of optional and user input for the typing. You should enable the flag below.
https://devblogs.microsoft.com/typescript/announcing-typescript-4-4/#exact-optional-property-types
@OliverNChalk Did you manage to resolve this?
I can't remember exactly anymore, did this link help (https://devblogs.microsoft.com/typescript/announcing-typescript-4-4/#exact-optional-property-types)
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.