【发布时间】:2021-12-05 22:44:23
【问题描述】:
当调用 firebase 可调用云函数时:
const myFunctions = require('/path/to/functions/src/index.js');
myFunctions.myTestFunc(data, {
auth: {
uid: myId
}
}).then(r => {
console.log("THIS IS THE ACTUAL RESPONSE FROM CLOUD FUNCTION", r);
})
我得到: 类型“void |”上不存在属性“then”承诺'。类型“void”上不存在属性“then”。
即使有问题的可调用函数显然返回了一个已解决的 Promise:
export const myTestFunc = functions.https.onCall(
async (data, context) => {
return new Promise((resolve) => {
resolve({success: true});
});
});
它仍然给出警告: const myTestFunc: (req: e.Request, resp: e.Response) => void |承诺
本质上是说在某些情况下会返回 void。但是,当我明确返回上述承诺时,我看不到情况如何。
任何关于正在发生的事情的想法将不胜感激。
【问题讨论】:
-
尝试深入了解 onCall 方法的定义。打字稿绑定说它返回什么?这就是你得到的,不管你作为处理函数传递什么。
标签: typescript firebase google-cloud-functions