Skip to content
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

Property 'logger' does not exist on type 'Request'. #172

Closed
johnboulder opened this issue Aug 18, 2022 · 2 comments
Closed

Property 'logger' does not exist on type 'Request'. #172

johnboulder opened this issue Aug 18, 2022 · 2 comments

Comments

@johnboulder
Copy link

I could very well be wrong on this, but it seems like the module augmentation done on the Request object is not implemented properly.

I found myself on a journey learning about Module Augmentation recently that was sparked by what you guys are doing in this project. I noticed when trying to use the logger decorator in hapi plugins written in typescript, my IDE was failing to recognize the property was added on the Request object.

Screen Shot 2022-08-18 at 9 07 55 AM

Through testing, I found that the logger worked as expected, so this just meant that there was something wrong with the type resolution.

While working with writing my own decorators in typescript, and making sure the Module Augmentation got picked up correctly, I stumbled across this on stack overflow, and realized why the augmented type wasn't being resolved when I tried to use the one declared here in hapi-pino. So I figured I'd share!

Also, I never used the server.logger, decorator, but for all I know it could be in the same boat.

TLDR

The module augmentation on the Request object, declared in this project's types, needs to be adjusted in order for it to be resolved correctly in typescript projects.

This

declare module '@hapi/hapi' {
  interface Request {
    logger: pino.Logger;
  }
}

Should look like this

declare module '@hapi/hapi' {
  interface Request extends Podium {
    logger: pino.Logger;
  }
}
@mcollina
Copy link
Collaborator

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@jonathansamines
Copy link
Contributor

I tried to reproduce this by adding some tests to the type definitions at #174. The existing declarations seems to work just fine. The test suit uses:

"@types/hapi__hapi": "^20.0.10",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants