• Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

90
Views
NodeJS "No overload matches this call." error with typescript

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};
9 months ago · Juan Pablo Isaza
1 answers
Answer question

0

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;

Have the same problem with importing

After changing the code

9 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.