-
Notifications
You must be signed in to change notification settings - Fork 135
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
Fix nodejs typing #281
Fix nodejs typing #281
Conversation
Hi @mhaligowski thanks for the fix. I wonder, how it will work in case Express-specific methods or properties are used. For example:
Since |
In the simple form, i.e. I think that the best way will be to just a TypeScript test to the test suite, but I don't really want to mess it up too bad with this PR. Let me see if I can modify the test routine so that we can start adding TypeScript tests as well. |
@eugef I added a PR with capability of writing TS test! Let me know if it's fine, and I'll rebase this PR on top of the TypeScript tests and will add some tests to make sure the current change works fine! |
Hi @mhaligowski PR #282 looks good to me. Feel free to proceed and add some tests. |
f7b666c
to
23a366a
Compare
Phew! Those tests were bigger than expected! Let me update the PR body with the explanation what I did. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @mhaligowski, big thanks for the tremendous amount of work you've put in!
This PR looks solid from my end. If you believe it's ready to be merged, I'll go ahead, and release a new minor version.
I think so, although it's still my first time messing with |
I'd suggest to make a pre-relase locally just for yourself and try this new version in some of your TS projects. |
Just did that! I ran Good to go from me! |
Great, thanks for testing. Could you also add a section to readme that explains how to use this lib with |
Opened #284! |
Is it possible to add documentation on how to use NextResponse with next.js's App router? as I keep getting TypeError: request.json is not a function as an error
|
Current types definition for the
node-mocks-http
library extend the HTTP requests and responses fromexpress
. As a result, HTTP request/response implementations from other frameworks (e.g.NextApiRequest
) are type-incompatible withnode-mocks-http
.This changes the generic class of the mock objects from the
Request
/Response
fromexpress
library to the NodeJSIncomingMessage/OutgoingMessage
in the type definition. Unless specified otherwise, the default generic type is still theexpress
object. It's inheriting from the NodeJS object, so it works fine. As a result, unless explicitly specified, there won't be any compatibility issues.UPDATE:
Adding TypeScript tests turned out a little more complicated than I initially expected, hence only the one for
mockRequest
. In the process of writing them I ran into couple of issues:declare module
, IIUC it is only needed when writing types declaration for external modules, not for within the same package,tsd
NPM package, which specifically tests the types.