Typescript 财产';然后';不存在于类型';云函数<;改变<;文档快照>&燃气轮机';

Typescript 财产';然后';不存在于类型';云函数<;改变<;文档快照>&燃气轮机';,typescript,firebase,google-cloud-firestore,google-cloud-functions,Typescript,Firebase,Google Cloud Firestore,Google Cloud Functions,错误:在我的firebase云函数上收到的类型“CloudFunction>”上不存在属性“then”,有人知道如何修复它吗 exports.rebuildFormTriggerClientDetails=functions.firestore。 文档('clientDetails/{details}')。onUpdate((更改)=>{ const afterDoc=change.after.data(); const documentId=change.after.id 如果(售后服务)

错误:在我的firebase云函数上收到的类型“CloudFunction>”上不存在属性“then”,有人知道如何修复它吗


exports.rebuildFormTriggerClientDetails=functions.firestore。
文档('clientDetails/{details}')。onUpdate((更改)=>{
const afterDoc=change.after.data();
const documentId=change.after.id
如果(售后服务)
{
让docUsers=db.collection(“clientDetails”).doc(documentId);
//var userMap:{[key:string]:any}={};
让caseArray:Array;
caseArray=afterDoc.caserevaray;
for(caseArray的var valCase){
控制台日志(valCase);
console.log(documentId);
createObjectDocument(docUsers,valCase);
}
}
}).然后(()=>{
log(“已成功更新文档!”);
}).catch((错误:任意)=>{
控制台错误(“更新文档时出错:”,错误);
});
这里是createObjectDocument函数。此功能可能是错误的原因吗


函数createObjectDocument(文档:任意,案例编号:字符串)
{
document.get().then(函数(doc:any){
如果(文件存在){
log(“文档数据:”,doc.data());
for(让Object.entries(doc.data())的[key,value]{
log(`${key}:${value}`);
如果(键!=“CaseRefArray”)
{
db.collection(“casesToExport”).doc(caseNumber).update({key:value});
}
}
}否则{
log(“没有这样的文档!”);
}
}).catch(函数(错误:任意){
log(“获取文档时出错:”,错误);
});
}

如下更改代码:

exports.rebuildFormTriggerClientDetails = functions.firestore.
document('clientDetails/{details}').onUpdate((change)  => {
  //const before = change.before;  // DataSnapshot before the change
  const afterDoc = change.after.data();
  const documentId = change.after.id

  if (afterDoc)

  {
    let docUsers = db.collection("clientDetails").doc(documentId);
    //var userMap: {[key: string]: any} = {};
    let caseArray: Array<string>;
    caseArray = afterDoc.CaseRefArray;

    for (var valCase of caseArray) {
      console.log(valCase); 
      console.log(documentId);

        createObjectDocument(docUsers,valCase);
    }
  }

});



function createObjectDocument(document: any, caseNumber: String)

{
  document.get().then(function(doc: any) {
    if (doc.exists) {
        console.log("Document data:", doc.data());
        for (let [key, value] of Object.entries(doc.data())) {
          console.log(`${key}: ${value}`);
         if (key != "CaseRefArray")
         {
          db.collection("casesToExport").doc(caseNumber).update({key : value })
            .then(() => {
                console.log("Successfully updated document!");
            }).catch((error: any) => {
                console.error("Error updating document: ", error);
            });
         }
        }
    } else {
        console.log("No such document!");
    }
}).catch(function(error: any) {
    console.log("Error getting document:", error);
});

}
exports.rebuildFormTriggerClientDetails=functions.firestore。
文档('clientDetails/{details}')。onUpdate((更改)=>{
//const before=change.before;//更改前的DataSnapshot
const afterDoc=change.after.data();
const documentId=change.after.id
如果(售后服务)
{
让docUsers=db.collection(“clientDetails”).doc(documentId);
//var userMap:{[key:string]:any}={};
让caseArray:Array;
caseArray=afterDoc.caserevaray;
for(caseArray的var valCase){
控制台日志(valCase);
console.log(documentId);
createObjectDocument(docUsers,valCase);
}
}
});
函数createObjectDocument(文档:任意,案例编号:字符串)
{
document.get().then(函数(doc:any){
如果(文件存在){
log(“文档数据:”,doc.data());
for(让Object.entries(doc.data())的[key,value]{
log(`${key}:${value}`);
如果(键!=“CaseRefArray”)
{
db.collection(“casesToExport”).doc(caseNumber).update({key:value})
.然后(()=>{
log(“已成功更新文档!”);
}).catch((错误:任意)=>{
控制台错误(“更新文档时出错:”,错误);
});
}
}
}否则{
log(“没有这样的文档!”);
}
}).catch(函数(错误:任意){
log(“获取文档时出错:”,错误);
});
}

您的
.then()
调用必须在您在数据库中更新文档时进行,这在您的
createObjectDocument()函数中完成。您能否提供您的
createObjectDocument()
方法。我添加了函数.db.collection(“casesToExport”).doc(caseNumber)。update({key:value})从来没有因为某种原因被调用过,也许是因为你有关键的价值?您的控制台日志是如何记录的
console.log(
${key}:${value}
返回?所有字段的格式与此客户端\u Mobile\u电话:07783602211相同,因此您确定您的if语句正确无误,或者您是否使用
console.log()
?我设法调用了该函数,但它只创建了一个新字段key:value。它似乎没有认识到关键价值