pino icon indicating copy to clipboard operation
pino copied to clipboard

pino.LoggerOptions.level type is incorrect

Open OliverNChalk opened this issue 4 years ago • 2 comments
trafficstars

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.

OliverNChalk avatar Oct 28 '21 12:10 OliverNChalk

cc @kibertoad

mcollina avatar Oct 28 '21 12:10 mcollina

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

climba03003 avatar Oct 30 '21 18:10 climba03003

@OliverNChalk Did you manage to resolve this?

Fdawgs avatar May 29 '23 08:05 Fdawgs

I can't remember exactly anymore, did this link help (https://devblogs.microsoft.com/typescript/announcing-typescript-4-4/#exact-optional-property-types)

OliverNChalk avatar May 29 '23 16:05 OliverNChalk

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.

github-actions[bot] avatar Jun 29 '23 00:06 github-actions[bot]