I’m using typescript to build a micro service in MERN stack but recently i have encountered an error with overload matches that point me to the index.d.ts file which I’m afraid to change
import express from "express";
import MyUserController from "../controllers/MyUserController";
const router = express.Router();
router.post("/", MyUserController.createCurrentUser);
export default router;
it bring a red line at:
router.post("/", MyUserController.createCurrentUser);
but also the code to my routes where inside the try catch block bring the error:
and especially the code: brings the error when i try to comment it out it goes away
if (existingUser) {
return res.status(200).send();
}
try {
const { auth0Id } = req.body;
const existingUser = await User.findOne({ auth0Id });
if (existingUser) {
return res.status(200).send();
}
const newUser = new User(req.body);
await newUser.save();
res.status(201).json(newUser.toObject());
} catch (error) {
console.log(error);
res.status(500).json({ message: "Error creating user" });
}
};
after trying to run the code it brought an error:
can anyone please help me solve this error:
return new TSError(diagnosticText, diagnosticCodes, diagnostics);
^
TSError: тип Unable to compile TypeScript:
src/routes/MyUserRoute.ts:6:18 - error TS2769: No overload matches this call.
The last overload gave the following error.
Argument of type '(req: Request, res: Response) => Promise<Response<any, Record<string, any>> | un
defined>' is not assignable to parameter of type 'Application<Record<string, any>>'.
Type '(req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<an
y, Record<string, any>>) => Promise<...>' is missing the following properties from type 'Application<R
ecord<string, any>>': init, defaultConfiguration, engine, set, and 63 more.
6 router.post("/", MyUserController.createCurrentUser);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@types/express-serve-static-core/index.d.ts:164:5
164 (path: PathParams, subApplication: Application): T;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The last overload is declared here.