Skip to content

New TypeScript types for logging reject many valid interpolation inputs #2266

@mdekstrand

Description

@mdekstrand

The new TypeScript types introduced in #2230 are much more strict than the functions accept, causing many false-positive typing errors in TypeScript code using Pino. #2259 is one example, but the overstrictness seems to go much farther.

  • The %s specifier in util.format will call obj.toString() if the object provides a toString() method, but the new typing rejects such objects as input to %s. Arbitrary objects with toString() are very useful when logging custom objects that have a natural string representation, such as a path or URL object.
  • %O and friends accept undefined (printing undefined) and null, but neither is allowed by the TypeScript types.

As near as I can tell, any JavaScript type seems to be valid input to %s, %O, and %o in util.format, so it seems that any would be a better input type for these format specifiers.

The result of this overstrictness is that code that type-checked prior to 9.8, and runs fine, now fails to typecheck with numerous errors (184 errors in 10K SLOC in one of my projects, that are spurious as far as I can tell).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions