Quick Fix
Add this JsDoc comment to your controllers:
/** @type {import("express").RequestHandler} */
exports.myController = (req, res) => {
// biz logic. ( here you would get intelliscence on req, res objects )
const { id } = req.query;
const { data } = req.body;
res.status(200).json({data});
}
Optional
If you are using typescript you can create a utility function to wrap your actual handler to avoid writing RequestHandler types on every controller.
// endpoint.ts
import { RequestHandler } from 'express';
export const endpoint = (cb: RequestHandler) => {
const handler: RequestHandler = (req, res, next) => {
cb(req,res,next)
}
return handler
}
// myController.ts
import { endpoint } from 'utils/endpoint';
export const myEndpoint = endpoint((req,res) => {
res.send("Hey!");
});