-
Notifications
You must be signed in to change notification settings - Fork 117
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
IncomingMessage and ServerMessage typings are too specific #294
Comments
+1, would you like to send a PR? |
sure! |
erunion
added a commit
to erunion/pino-http
that referenced
this issue
Aug 30, 2023
The typings on the various instances of `IncomingMessage` and `ServerResponse` are too strict when coupled with Express and Fastify `Request` instances that have been extended for custom properties. This loosens them up by allowing the main `pino` instance to be supplied a generic of the Request and Response interfaces that you use in your application. Fixes pinojs#294
mcollina
pushed a commit
that referenced
this issue
Sep 4, 2023
…#295) The typings on the various instances of `IncomingMessage` and `ServerResponse` are too strict when coupled with Express and Fastify `Request` instances that have been extended for custom properties. This loosens them up by allowing the main `pino` instance to be supplied a generic of the Request and Response interfaces that you use in your application. Fixes #294
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We're gradually migrating our Express and Fastify hybrid codebase over to Typescript and have begun running into issues with various data we have in our Request objects:
The above code works normally in JS but in TS
req.project
is undefined because it does not exist on thecustomProps
req
parameter ofIncomingMessage
. We're already overloading the ExpressRequest
object to allow forreq.proejct
exist, but adding that, and everything else we're adding to that is a non-starter for us:I have tried to type
req
asreq: Request
but even though Express'Request
extendsIncomingMessage
theIncomingMessage
typing on that is too specific:I have also attempted to monkeypatch the
Options
interface to allow us to typereq
andres
asRequest
andResponse
but TS doesn't like that either:It would be really nice if when calling
pino()
we could supply it with a generic of our Express and FastifyRequest
andResponse
interfaces and let that populate down into whereverIncomingMessage
andServerResponse
are being used. Something like this:The text was updated successfully, but these errors were encountered: