我正在尝试从集合中获取一些文档,然后将它们写入具有云功能的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
})
})