I'm trying to create NodeJS app from scratch with typescript addition... I was following some tutorial and basically did the same steps as he did yet he didn't receive this error... Did NodeJS or TypeScript get some kind of updates that are causing this error?
Problem is that I'm receiving error on index.ts file POST with getAllUsers controller and I have no clue what is it about:
No overload matches this call. The last overload gave the following error. Argument of type '(req: Request, res: Response) => Promise' is not assignable to parameter of type 'Application<Record<string, any>>'. Type '(req: Request, res: Response<any, Record<string, any>>) => Promise' is missing the following properties from type 'Application<Record<string, any>>': init, defaultConfiguration, engine, set, and 61 more.
Any help is welcome :)
index.ts file:
import * as functions from "firebase-functions";
import * as express from "express";
import {getAllUsers } from "./controllers/usersController";
const app = express();
app.post("/users",getAllUsers);
app.get("/", (req, res) => res.status(200).send("default route!"));
exports.app = functions.https.onRequest(app);
Controller file:
const getAllUsers = async (req: Request, res: Response) => {
let userArray: any[] = [];
try {
const user = await db.collection("userInfo").get();
if (!user.docs) {
res.status(404).send("not found");
} else {
user.docs.forEach((user) =>
userArray.push({id: user.id, user: user.data()})
);
}
res.status(200).send("<p>some html</p>");
} catch (error) {
res.status(500).send("error.message");
}
};
export {getAllUsers};
I got stuck for hours for this one. I hope this helped.
Try changing the format of the code from
import {getAllUsers } from "./controllers/usersController";
&
export {getAllUsers};
to
import getAllUsers from "./controllers/usersController";
&
export default getAllUsers;