-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve PluginSpecificConfiguration intellisense adding Refs generic #4526
Labels
feature
New functionality or improvement
Comments
This is the patch i made with pnpm diff --git a/lib/types/plugin.d.ts b/lib/types/plugin.d.ts
index 2be5b9cf39add13eb99a1ad2490965b74b13e444..31a3675d95e6d366dbd464f516ec869632fdd110 100644
--- a/lib/types/plugin.d.ts
+++ b/lib/types/plugin.d.ts
@@ -1,4 +1,4 @@
-import { RequestRoute } from './request';
+import { RequestRoute, ReqRef, ReqRefDefaults } from './request';
import { RouteOptions } from './route';
import { Server } from './server';
import { Lifecycle } from './utils';
@@ -47,7 +47,7 @@ export interface PluginRegistered {
export interface PluginsStates {
}
-export interface PluginSpecificConfiguration {
+export interface PluginSpecificConfiguration<Refs extends ReqRef = ReqRefDefaults> {
}
export interface PluginNameVersion {
diff --git a/lib/types/route.d.ts b/lib/types/route.d.ts
index be2416850c89f295f53cbf756afaf7dd3055a5dd..102226d055dfafa080b239c442dd9979a93970bd 100644
--- a/lib/types/route.d.ts
+++ b/lib/types/route.d.ts
@@ -788,7 +788,7 @@ export interface CommonRouteProperties<Refs extends ReqRef = ReqRefDefaults> {
* Plugin-specific configuration. plugins is an object where each key is a plugin name and the value is the plugin configuration.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsplugins)
*/
- plugins?: PluginSpecificConfiguration | undefined;
+ plugins?: PluginSpecificConfiguration<Refs> | undefined;
/**
* @default none. |
@lgraziani2712 can you try cloning hapi and testing this? We need to be sure this doesn't break existing typings. Send a PR. I'm for it, but the reqrefdefaults can cause some pain downstream (tricky to type); it already does with pres and ext helpers of sorts. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
With that, we could configure plugins like this
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
The text was updated successfully, but these errors were encountered: