在以前编译的代码上引发Firebase CLI Typescript错误TS2345



晚上好,

我最近为云功能更新了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(几年前(中找到了一个示例函数,其中的结构与我展示它的方式相同,这告诉我最近一定有什么变化。

https://github.com/firebase/functions-samples/blob/master/quickstarts/time-server/functions/index.js#L39

其他规格:
Windows 10
NPM版本14.5.0
Firebase工具版本8.6.0

有什么想法或建议吗?是否有简单的代码更改,或者我应该恢复到旧版本的CLI或tslint?

感谢您提前抽出时间!

他们最近更改了https触发器的返回类型。

你不应该"返回";任何作为回应的东西。

只要删除return,就可以继续了。

示例:

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
res.status(200).send("ok");
}
});