ошибка TS2532: возможно, объект не определен - PullRequest
0 голосов
/ 02 ноября 2019

Я не могу развернуть функцию 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);
            }
        }

Я пробовал: if (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

...