【问题标题】:Parameter result implicitly has any type参数结果隐式具有任何类型
【发布时间】:2020-02-20 07:34:40
【问题描述】:

我有一个聊天应用程序,我正在尝试为所有订阅者发送通知。我必须遍历用户以使用 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);
    });

不知道为什么结果有这个错误,但它不会让我上传到云功能。任何帮助将不胜感激。

【问题讨论】:

  • 错误是“Uncaught SyntaxError: Cannot use import statement outside a module”吗?
  • 错误是什么?
  • 错误是特定于 .forEach 循环的......“结果”有波浪线,当我将鼠标悬停时它说,参数结果隐含任何类型

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


【解决方案1】:

看起来可能是 tslint 问题。您可能需要将类型声明为不允许隐式使用“任何”。它必须是明确的。

试试这个:

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

【讨论】:

    猜你喜欢
    • 2018-05-30
    • 2021-06-09
    • 2018-09-17
    • 2021-07-20
    • 1970-01-01
    • 2023-03-08
    • 2020-02-02
    • 2019-11-21
    • 2021-03-29
    相关资源
    最近更新 更多