【发布时间】:2020-11-07 20:46:16
【问题描述】:
晚上好,
我最近更新了用于云功能的 firebase CLI,当我尝试部署旧的 index.ts 文件时,出现 TS2345 错误:
src/index.ts:364:13 - error TS2345: Argument of type '(req: Request, res: Response<any>) => Response<any> | Promise<void | Response<any>>' is not assignable to parameter of type '(req: Request, resp: Response<any>) => void | Promise<void>'.
Type 'Response<any> | Promise<void | Response<any>>' is not assignable to type 'void | Promise<void>'.
Type 'Response<any>' is not assignable to type 'void | Promise<void>'.
Type 'Response<any>' is not assignable to type 'Promise<void>'.
364 .onRequest((req, res) => {
引发此错误的函数如下所示:
exports.https_rec = functions.https
.onRequest((req, res) => {
if (req.method === 'PUT') {
console.log("HTTPS Attempted Connection");
return res.status(403).send('Forbidden!');
}
else{
//Do Stuff
return res.status(200).send("ok");
}
});
一切正常且上传正常,但在我更新 CLI 后,我现在在之前编译的代码上收到此 TS2345 错误。我从 Firebase 中找到了一个示例函数(几年前),其中的结构与我展示它的方式相同,这告诉我最近一定发生了一些变化。
其他规格:
视窗 10
NPM 版本 14.5.0
Firebase-tools 版本 8.6.0
有什么想法或建议吗?是否可以轻松更改代码,或者我应该恢复到旧版本的 CLI 或 tslint?
提前感谢您的宝贵时间!
【问题讨论】:
标签: node.js typescript firebase