Open mattgif opened 1 year ago
Which version of typescript are you using? I had the same thing for versions < 4.9.
Which version of typescript are you using? I had the same thing for versions < 4.9.
v4.9.5
My workaround for now is an interface declaration like so:
export interface RequestWithPlugins<DataParams = Record<string,any>,QueryParams extends RequestQuery = Record<string,any>> extends Request {
server: Server<ServerApplicationState> & {
plugins: MyPlg & MyOtherPlg & YetAnotherPlg;
query?: QueryParams;
data?: DataParams;
};
}
Where my plugin interfaces look something like:
interface MyPlg extends PluginProperties {
MyPlugin: {
foo: {
bar: 'Hello, world';
};
};
}
Support plan
Context
How can we help?
What is the recommended approach for declaring the typescript interface for PluginProperties in Hapi 21?
Formerly (upgrading from Hapi 17), we could do this by declaring a module. But doing this in v21 with multiple plugins yields the following error at runtime:
error TS2339: Property 'X' does not exist on type 'PluginProperties'.
(where 'X' is the name of some declared plugin).In the code example below handler.ts is the module that throws the error:
myPlugin.ts
anotherPlg.ts
handler.ts
index.ts