-
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
Incorrect Types for decorators #4524
Labels
types
TypeScript type definitions
Comments
I agree. The typings are incorrect, confirmed by the API docs, and the code and tests. Except for A PR to fix this would be appreciated. When fixing this, take care to preserve the existing behaviour of adding the correct server.decorate('server', 'myFunc', function () {
this.inject(…);
}); |
feedmypixel
added a commit
to feedmypixel/hapi
that referenced
this issue
Aug 26, 2024
- The code currently allows any value to be added as a decorator, but the types do not. This work allows any value to be added to a decorator by updating the types to reflect what the code doeis - Add relevant tests - Update inline docs - Create and export DecorationValue type - Fixes hapijs#4524
feedmypixel
added a commit
to feedmypixel/hapi
that referenced
this issue
Aug 26, 2024
- The code currently allows any value to be added as a decorator, but the types do not. This work allows any value to be added to a decorator by updating the types to reflect what the code does - Add relevant tests - Update inline docs - Create and export DecorationValue type - Fixes hapijs#4524
feedmypixel
added a commit
to feedmypixel/hapi
that referenced
this issue
Aug 26, 2024
- The code currently allows any value to be added as a decorator, but the types do not. This work allows any value to be added to a decorator by updating the types to reflect what the code does - Add relevant tests - Update inline docs - Create and export DecorationValue type - Fixes hapijs#4524
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Runtime
Node.js
Runtime version
v20.11.1
Module version
@hapi/hapi v21.3.10
What are you trying to achieve or the steps to reproduce?
Trying to add an
object
via a decorator to server. Whilst using JSDOC/TypeScript and we are getting an error we have to disable.What we can do
When using decorators you can provide any value as the
method
argument and Hapis internals will add it to the interface being decorated.fEx:
The example in Hapi code for a server decorator can be seen in lib/server.js#L182
What the Types say you can do
However the Types only allow for functions:
And the docs hint that it is intended that the
method
argument is used with other values:Are we using this correctly?
object
via a decoratorsmethod
argument toServer
correct?Server.app
? OrRequest.app
?Can we raise a PR?
Is an update to the Types around decorators to allow non functions to be passed to
method
a PR you would accept?What was the result you got?
We have to bypass decorators that have a non function value provided to the
method
argument with// @ts-expect-error
What result did you expect?
According to the code, to be able to add any value via a decorators
method
argumentThe text was updated successfully, but these errors were encountered: