javascript - 参数结果隐式具有任何类型
问题描述
我有一个聊天应用程序,我正在尝试为所有订阅者发送通知。我必须遍历用户以使用 where 子句中的 ID 来获取他们的设备令牌
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);
});
不知道为什么结果有这个错误,但它不会让我上传到云功能。任何帮助将不胜感激。
解决方案
看起来这可能是一个 tslint 问题。您可能需要将类型声明为“任何”不允许隐式。它必须是明确的。
试试这个:
devices.forEach((result: any) => {
推荐阅读
- php - 移动设备通知
- excel - #value 使用 Google Maps API 密钥计算 excel 距离时出错
- javascript - Angular 4:按钮组件的禁用行为
- python - Python 为字典中的每个条目运行脚本
- azure-functions-core-tools - 如何在 Logic App 中选择一种以上的翻译语言?
- python - ModuleNotFoundError:没有名为“_ctype”的模块
- android - 使用长写入构建器在每次批量写入之间添加延迟
- spring-boot - 在升级到 Spring Boot 2.0 时,得到 UnsatisfiedDependencyException
- actionscript-3 - 如何使滚动窗格中文本字段的自动换行正常工作并且不触发水平滚动
- c - CS50 问题集 1(现金/贪婪算法)出现运行时错误:有符号整数溢出