-
-
Notifications
You must be signed in to change notification settings - Fork 17.7k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Getting error while using " return res.json({ }) " #6022
Comments
the problem was in @types/[email protected] , when i used previous version the issue was solved |
EDIT: THIS COMMENT IRRELEVANT Looking to lend a hand, what help do you want here? More info on the bug, updated types for 5.0, overload that allows res return? |
Q1: is it express intention to not call next and return out of a middleware? Doco is only representative of calling next(), to handle errors out of them it's handed to custom error handler EDIT: BELOW IRRELEVANT Note1: I have looked at the types that are throwing in types/express-serve-static-core, they seem to have no changes since v4. This was a quick look. Will get to more work over the weekend |
It seems that types for 5 are working as intended because next is the intention of middleware instead of returning directly out of them. |
Related issue #5987 |
Hey @tanmayvaij hope you find well, so basically something that you can do with that version of @types/[email protected] is changing a little bit your approach instead of using
|
This issue is related to this interface in express-serve-static-core
adding the |
The error you're encountering occurs because the tokenVerifier middleware returns a response in case of an error (res.json(...)). The RequestHandler type from Express expects the middleware to either return void or Promise. Since tokenVerifier is returning Response | undefined, TypeScript throws this error. Here’s how to address it: Ensure that tokenVerifier always calls next() or returns when it’s done, without returning any response directly. Here's an updated version of tokenVerifier:
Changes Explained The return type for tokenVerifier is set to void, making sure it either calls next() or returns a response without breaking Express's expected type. If you still encounter issues, make sure that your route handler (verifyUserController) is also typed correctly and doesn’t directly return a response. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
using "express": "^4.21.0",
created this middleware for token verification
i get this err while starting the server
The text was updated successfully, but these errors were encountered: