I'm creating a cloud function using Firebase to search for "waiting rooms", since I'm using "limitToLast" to get only the last child on the "rooms" node I have to loop through the snapshot children to get the data snapshot for the room I want (I don't know if there's a better way to do so, but it worked just fine before), the thing is that I need to check some things after assigning the "waitingRoomData" inside the "forEach" but I'm getting a message saying: "Property does not exist on type 'never'". I've never worked with typescript before and have no clue how to solve this.
let waitingRoomData;
//Join waiting room.
waitingRoomsSnapshot.forEach(waitingRoom => {
waitingRoomData = waitingRoom;
});
if (waitingRoomData === undefined) {
return undefined;
} else {
if (waitingRoomData.child('hostId').val() == context.auth?.uid) {
//Uses an existing room where the current user is the host.
//Update creation time.
return waitingRoomData.child('creationTime').ref.set(admin.database.ServerValue.TIMESTAMP).then(() => {
return waitingRoomData.val();
}).catch(error => {
console.log(error);
return error;
});
} else {
return waitingRoomData.val();
}
}