I'm trying to deploy firebase functions and I get the error
src/index.ts(132,31): error TS2339: Property 'data' does not exist on type 'Change'. src/index.ts(136,65): error TS2339: Property 'params' does not exist on type 'Change'. src/index.ts(142,18): error TS2339: Property 'data' does not exist on type 'Change'.
my code
module.exports.onUserStatusChanged = functions.database
.ref('/users/{uid}').onUpdate((event) => {
// Get the data written to Realtime Database
const eventStatus = event.data.val();
// Then use other event data to create a reference to the
// corresponding Firestore document.
const userStatusFirestoreRef = firestore.doc(`users/${event.params.uid}`);
// It is likely that the Realtime Database change that triggered
// this event has already been overwritten by a fast change in
// online / offline status, so we'll re-read the current data
// and pare the timestamps.
return event.data.ref.once("value").then((statusSnapshot) => {
return statusSnapshot.val();
}).then((status) => {
console.log(status, eventStatus);
// If the current timestamp for this data is newer than
// the data that triggered this event, we exit this function.
if (status.last_changed > eventStatus.last_changed) return;
// Otherwise, we convert the last_changed field to a Date
eventStatus.last_changed = new Date(eventStatus.last_changed);
// ... and write it to Firestore.
//return userStatusFirestoreRef.set(eventStatus);
return userStatusFirestoreRef.update(eventStatus);
});
});
it shows red undeline
event.data.val()
event.params.uid
I'm trying to deploy firebase functions and I get the error
src/index.ts(132,31): error TS2339: Property 'data' does not exist on type 'Change'. src/index.ts(136,65): error TS2339: Property 'params' does not exist on type 'Change'. src/index.ts(142,18): error TS2339: Property 'data' does not exist on type 'Change'.
my code
module.exports.onUserStatusChanged = functions.database
.ref('/users/{uid}').onUpdate((event) => {
// Get the data written to Realtime Database
const eventStatus = event.data.val();
// Then use other event data to create a reference to the
// corresponding Firestore document.
const userStatusFirestoreRef = firestore.doc(`users/${event.params.uid}`);
// It is likely that the Realtime Database change that triggered
// this event has already been overwritten by a fast change in
// online / offline status, so we'll re-read the current data
// and pare the timestamps.
return event.data.ref.once("value").then((statusSnapshot) => {
return statusSnapshot.val();
}).then((status) => {
console.log(status, eventStatus);
// If the current timestamp for this data is newer than
// the data that triggered this event, we exit this function.
if (status.last_changed > eventStatus.last_changed) return;
// Otherwise, we convert the last_changed field to a Date
eventStatus.last_changed = new Date(eventStatus.last_changed);
// ... and write it to Firestore.
//return userStatusFirestoreRef.set(eventStatus);
return userStatusFirestoreRef.update(eventStatus);
});
});
it shows red undeline
event.data.val()
event.params.uid
Share
edited Apr 17, 2018 at 21:10
Peter Haddad
81k25 gold badges145 silver badges146 bronze badges
asked Apr 17, 2018 at 20:33
ManspofManspof
35727 gold badges94 silver badges183 bronze badges
1
-
check the answer, also im not sure if you are using cloud firestore. If you are using cloud firestore then you need to be using
exports.onUserStatusChanged = functions.firestore.document('/path').onUpdate((change,context) => {
Also check the firestore section firebase.google./docs/functions/beta-v1-diff#cloud-firestore – Peter Haddad Commented Apr 17, 2018 at 20:54
1 Answer
Reset to default 10Change this:
module.exports.onUserStatusChanged = functions.database
.ref('/users/{uid}').onUpdate((event) => {
// Get the data written to Realtime Database
const eventStatus = event.data.val();
into this:
module.exports.onUserStatusChanged = functions.database
.ref('/users/{uid}').onUpdate((change,context) => {
// Get the data written to Realtime Database
const eventStatus = change.after.val();
Also change this:
event.params.uid
into this:
context.params.uid
more info here:
https://firebase.google./docs/functions/beta-v1-diff
Cloud functions have been updated and to retrieve data after onWrite
is triggered, you need to use change
that has two properties before and after, in this case use change.after.val()