hapi-pino icon indicating copy to clipboard operation
hapi-pino copied to clipboard

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

Open sveisvei opened this issue 3 years ago • 3 comments

  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
    },
  });

sveisvei avatar Jul 17 '22 19:07 sveisvei

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

mcollina avatar Jul 17 '22 20:07 mcollina

@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.

jonathansamines avatar Aug 25 '22 03:08 jonathansamines

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

mcollina avatar Aug 25 '22 12:08 mcollina