hapijs / hapi-pino

🌲 Hapi plugin for the Pino logger
MIT License
148 stars 60 forks source link

Using typescript and import gives type error: No overload matches this call. #171

Closed sveisvei closed 2 months ago

sveisvei commented 2 years ago
  import pinoHapiPlugin from "hapi-pino";

  server.register({
    plugin: pinoHapiPlugin,
    options: {
     // ...options
    },
  });

Will give type error

No overload matches this call.
  The last overload gave the following error.
    Argument of type '{ plugin: Hapi.Plugin<pinoHapiPlugin.Options>; options: { level: pino.Level; logRequestComplete: boolean; prettyPrint: boolean; redact: string[]; ignorePaths: string[]; instance: pino.Logger<...> | undefined; }; }' is not assignable to parameter of type 'Plugin<any> | Plugin<any>[]'.
      Object literal may only specify known properties, and 'plugin' does not exist in type 'Plugin<any> | Plugin<any>[]'.ts(2769)
index.d.ts(3886, 5): The last overload is declared here.

While getting no typescript error if using require:

  server.register({
    plugin: require("hapi-pino"),
    options: {
     // ...options
    },
  });
mcollina commented 2 years ago

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

jonathansamines commented 2 years ago

@sveisvei I think you can use the import * syntax instead:

import * as HapiPino from 'hapi-pino';

@mcollina I looked it up and seems like this is solvable by changing the export syntax, though from typescript docs seems like the change would not be backwards compatible (See docs). Not really sure we can simply change this without breaking existing consumers.

mcollina commented 2 years ago

I'm not actively using this module nor typescript, so I'd defer to your best recommendation.