简体   繁体   中英

Parameter result implicitly has any type

在此处输入图像描述 I have a chat app where I'm trying to send notifications for all of the subscribers. I have to iterate through the users to use the ID's in the where clause to grab their device tokens

 import * as functions from 'firebase-functions'; import * as admin from 'firebase-admin'; admin.initializeApp(); exports.newTopicNotification = functions.firestore.document('topics/{id}/topic/{doc}/chat/{chat}').onWrite( async event => { const allMessages = event.after.data(); const db = admin.firestore(); let data: any; if (allMessages) { data = allMessages; } const title = data? data.title: ''; const topicId = data? data.topicId: ''; const groupId = data? data.groupId: ''; console.log('incomingData', data); const payload = { notification: { title: 'New group topic post', body: `${title}` } }; let users: any = []; let devices: any = []; const tokens: any = []; users = await db.collection('topics').doc(`${groupId}`).collection('topic').doc(`${topicId}`).get(); console.log('users', users.data().subscribers); for (let i = 0; i < users.data().subscribers.length; i++) { const devicesRef = db.collection('devices').where('userId', '==', users.data().subscribers[i]); const device = await devicesRef.get(); devices.push(device); console.log('device', devices); } // here the result keeps showing the error devices.forEach(result => { const token = result.data().token; tokens.push(token); }); return admin.messaging().sendToDevice(tokens, payload); });

Not sure why result has that error but it won't let me upload to cloud functions as a result. Any help would be greatly appreciated.

Looks like it could be a tslint issue. You may need to declare the type as "any" is not allowed implicitly. It has to be explicit.

Try this:

devices.forEach((result: any) => {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM