#4526·hapi

Improve PluginSpecificConfiguration intellisense adding Refs generic

Author: lgraziani2712Created Aug 28, 2024Updated Sep 30, 2024
Labelsfeature

Runtime

NodeJS

Runtime version

22.7.0

Module version

21.3.10

Used with

hapi application

Any other relevant information

No response

What problem are you trying to solve?

I'm trying to write a plugin that accepts a function that receives the request as a param and it could be nice to have the generic from the route shared to plugins, something like the following:

typescript
// plugin.d.ts
interface PluginSpecificConfiguration<Refs extends ReqRef = ReqRefDefaults> {}

// routes.d.ts
interface CommonRouteProperties<Refs extends ReqRef = ReqRefDefaults> {
    plugins?: PluginSpecificConfiguration<Refs> | undefined;
}

With that, we could configure plugins like this

typescript
declare module '@hapi/hapi {
  interface PluginSpecificConfiguration<Refs extends ReqRef = ReqRefDefaults> {
    pluginName: PluginInterface<Refs>;
  }
}

I'm interested in writting a PR if y'all accept the idea :)

Do you have a new or modified API suggestion to solve the problem?

No response