繁体   English   中英

NodeJS“没有重载匹配这个调用。” 打字稿错误

[英]NodeJS "No overload matches this call." error with typescript

我正在尝试使用 typescript 添加从头开始创建 NodeJS 应用程序...我正在遵循一些教程,并且基本上做了与他相同的步骤,但他没有收到此错误... NodeJS 或 TypeScript 是否获得了某种更新导致此错误的原因是什么?

问题是我在使用 getAllUsers 控制器的 index.ts 文件 POST 上收到错误,我不知道它是关于什么的:

没有重载匹配此调用。 最后一个重载给出了以下错误。 '(req: Request, res: Response) => Promise' 类型的参数不能分配给 'Application<Record<string, any>>' 类型的参数。 类型 '(req: Request, res: Response<any, Record<string, any>>) => Promise' 缺少来自类型 'Application<Record<string, any>>' 的以下属性:init、defaultConfiguration、engine、集,还有 61 个。

欢迎任何帮助:)

index.ts 文件:

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);

控制器文件:

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};

我为此卡了几个小时。 我希望这会有所帮助。 尝试更改代码的格式
import {getAllUsers } from "./controllers/usersController"; & export {getAllUsers};

import getAllUsers from "./controllers/usersController"; & export default getAllUsers;

导入时遇到同样的问题

修改代码后

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM