【问题标题】:Google Cloud Function undefined argument detected as null谷歌云函数未定义参数检测为空
【发布时间】:2021-01-13 02:53:14
【问题描述】:

当我将未定义的参数传递给我的云函数时,它被检测为 null。例如,如果我有这个:

 const a = undefined;

 firebase.functions().httpsCallable("myFunction")({
    a
 });

在我的云功能中我会这样做:

...
.https.onCall(async (data, context) => {

    const {a} = data;

    console.log(a);

    ...
});

它打印“null”而不是“undefined”。

我的功能:空

为什么?

【问题讨论】:

    标签: javascript node.js firebase google-cloud-platform google-cloud-functions


    【解决方案1】:

    当您调用远程函数时,有效负载(即您的data)被序列化:

    Serializer 所做的第一个操作(针对每个属性)是:

    if (data == null) {
       return null;
    }
    

    由于使用== 代替===,所以undefined 变成了null

    【讨论】:

      猜你喜欢
      • 2020-03-18
      • 2019-06-28
      • 1970-01-01
      • 2019-04-06
      • 2020-08-11
      • 2021-07-09
      • 2019-02-15
      • 2018-12-07
      • 2018-10-02
      相关资源
      最近更新 更多