0

I'm unable to deploy a firebase function as a result of the following error:

enter image description here

Here's the code...really simple

        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);
            }
        }

I've tried: if (notify.data().sendNotify) {isNotifyTrue = notify.data().sendNotify; }

and

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

and I've tried:

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

also tried:

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

as a result ofenter image description here

D.Hodges
  • 1,198
  • 2
  • 12
  • 26
  • 1
    Does this answer your question? [How can I solve the error 'TS2532: Object is possibly 'undefined'?](https://stackoverflow.com/questions/54884488/how-can-i-solve-the-error-ts2532-object-is-possibly-undefined) – Robert Harvey Nov 02 '19 at 15:59
  • I tried that one too to no avail: src/index.ts:56:44 - error TS2532: Object is possibly 'undefined'. 56 if (notify && notify.data() && notify.data().sendNotify) { – D.Hodges Nov 02 '19 at 16:05
  • https://shinesolutions.com/2017/01/06/writing-safer-code-with-typescript-strict-null-checks-type-guards/ – Robert Harvey Nov 02 '19 at 16:12
  • @RobertHarvey I do. It's a warning that notify.data().sendNotify could possibly be undefined. But I'm checking if it's undefined and it still gives me the error. – D.Hodges Nov 02 '19 at 19:00
  • I'm not sure the compiler is smart enough to make that distinction. If you're sure that it's never going to be undefined, I'd just ignore the warning. – Robert Harvey Nov 02 '19 at 19:14
  • @RobertHarvey there's not way to ignore the warning when attempting to deploy the firebase function to firebase cloud functions that I know of. But I'm sure it won't be null. How do you ignore the warning – D.Hodges Nov 02 '19 at 21:27
  • By not paying any attention to it. – Robert Harvey Nov 03 '19 at 04:38
  • @RobertHarvey firebase cloud function won't let you upload with those errors – D.Hodges Nov 03 '19 at 14:52

0 Answers0