![](/img/trans.png)
[英]No overload matches this call. The last overload gave the following error in typescript
[英]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.