You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Which suggests to plugin creators to export their package as Plugin<Opts>.
The problem lies in that, when make tooling around Hapi, if I want to signal a dependency on another plugin in Typescript, I can't depend on MyPlugin.name because it is an intersection between PluginNameVersion | PluginPackage.. One doesn't contain name. The following will throw a TS error:
importHapiSwaggerfrom'hapi-swagger';exportconstmyThing=(server: Hapi.Server)=>{// This package exports as `PluginNameVersion`server.depedency(HapiSwagger.name);// Property 'name' does not exist on type 'PluginBase<RegisterOptions, void> & PluginPackage'}
We should have the option to export both:
// Allows proper typing of the specific package use-caseexporttypeNamedPlugin<T,D=void>=PluginBase<T,D>&PluginNameVersion;exporttypePackagedPlugin<T,D=void>=PluginBase<T,D>&PluginPackage;// won't break existing functionalityexporttypePlugin<T,D=void>=NamedPlugin<T,D>|PackagedPlugin<T,D>;
What are you trying to achieve or the steps to reproduce?
Specificity in the type of plugin exported
What was the result you got?
Property 'name' does not exist on type 'Plugin<RegisterOptions>'.
Property 'name' does not exist on type 'PluginBase<RegisterOptions, void> & PluginPackage'.ts(2339)
What result did you expect?
I expect to be able to use MyPlugin.name with a utility from Hapi itself
The text was updated successfully, but these errors were encountered:
This makes a lot of sense, though it only solves the issue for plugins that are updated to export its subtype. Otherwise you would still need to cast it, as you can right now:
(HapiSwaggerasPluginNameVersion).name
Much care should be taken when updating hapi typings that plugins rely on. Otherwise, the plugin could have to choose between supporting the old version, or updated version.
In this case, updated plugins might choose to use the new types for better integration, with the consequence that it can no longer be used with older hapi releases.
FYI, I would prefer if they are declared as interfaces:
Runtime
typescript
Runtime version
5
Module version
21
Last module version without issue
n/a
Used with
Other plugins or tools
Any other relevant information
Currently, the typing for Hapi is
Which suggests to plugin creators to export their package as
Plugin<Opts>
.The problem lies in that, when make tooling around Hapi, if I want to signal a dependency on another plugin in Typescript, I can't depend on
MyPlugin.name
because it is an intersection betweenPluginNameVersion | PluginPackage
.. One doesn't containname
. The following will throw a TS error:We should have the option to export both:
What are you trying to achieve or the steps to reproduce?
Specificity in the type of plugin exported
What was the result you got?
What result did you expect?
I expect to be able to use
MyPlugin.name
with a utility from Hapi itselfThe text was updated successfully, but these errors were encountered: