错误TS2532:对象可能是“未定义”

时间:2019-11-02 15:26:29

标签: javascript push-notification firebase-cloud-messaging ionic4

由于以下错误,我无法部署Firebase函数:

enter image description here

这是代码...真的很简单

        for (let i = 0; i < users.data().subscribers.length; i++) {
            const addToken = (userId === users.data().subscribers[i]);
            const notify = await db.collection('users').doc(`${users.data().subscribers[i]}`).get();
            if (notify.data().sendNotify) {isNotifyTrue = notify.data().sendNotify; }

            console.log('isNotifyTrue', notify.data().sendNotify);
            if ((!addToken) && (!isNotifyTrue)) {
                const devicesRef = db.collection('devices').where('userId', '==', users.data().subscribers[i]);
                const device = await devicesRef.get();
                devices.push(device);
                console.log('device', device);
                console.log('devices', devices);
            }
        }

我尝试过:             如果(notify.data()。sendNotify){isNotifyTrue = notify.data()。sendNotify; }

        if (notify) {isNotifyTrue = notify.data().sendNotify; }

我已经尝试过:

        isNotifyTrue = notify.data().sendNotify ? notify.data().sendNotify : true;

也尝试过:

            if ((notify.data().sendNotify !== 'undefined') || (notify.data() !== null) || notify.data() !== undefined) {
                sendNotify =  notify.data().sendNotify; }

enter image description here

的结果

0 个答案:

没有答案