I have the following code in typescript and i get this error on the line: change.after.data();, Object is posibbly 'undefined':
import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
admin.initializeApp()
export const onEditModeUpdate =
functions.firestore.document("Settings/ShiftsEditMode").onUpdate(change=> {
const after = change.after.data();
const payload = {
data: {
temp: String(after.temp),
conditions: after.conditions
}
}
return admin.messaging().sendToTopic("Settings/ShiftsEditMode", payload)
})
what I want to do is to send to my app a notification whenever something in firestore changes, I followed the official documentation but I get the error, I think this has to do with node.js version. Any help, please?