Firestore Cloud功能的承诺存在问题

时间:2020-04-11 16:49:39

标签: typescript google-cloud-firestore google-cloud-functions

我正在尝试从集合中获取一些文档,然后将它们写入具有云功能的Firestore中的另一个集合中。

当我尝试退还所有诺言时,出现此错误:Variable 'promises' implicitly has type 'any[]' in some locations where its type cannot be determined.ts(7034)

这是为什么?这也是做我上面解释的好方法吗?

export const follow = 
    functions.firestore.document('users/{uid}/following/{userFollowing}').onWrite((snap,context) 
    =>{
      const userFollowing = context.params.userFollowing
      const uid = context.params.uid

      admin.firestore().collection('posts').where('uid','==',userFollowing).get()  
      .then(snapshots =>{
        const promises = []    
        snapshots.forEach(doc =>{
          const p = admin.firestore().doc(`users/${uid}/timeline/${doc.id}`).set(doc) 
          promises.push(p)       
        })
        return Promise.all(promises)
      })

      .catch(error =>{
        //handle error
      })

})

0 个答案:

没有答案