0

I'm getting the warning 'Unreachable code detected' in my typescript file. Nothing works after running a Firebase transaction. Here's the transaction code:

// Create Firestore reference
let pointsRef = 'Users/'+this.user.uid;
var pointsDocRef = this.afs.doc(pointsRef).ref;

return this.afs.firestore.runTransaction((transaction) => {
  return transaction.get(pointsDocRef).then((ptsDoc) => {
    if(!ptsDoc.exists){
      throw "Document does not exist!"
    }

    var newPtsScore = ptsDoc.data().points - 20;
    transaction.update(pointsDocRef, { points: newPtsScore });             
  });
}).then(() => {
  console.log('Point count successfully decremented for new item'); 
  // Close dialog
  this.dialog.closeAll();
}).catch(function(error) {console.log('Transaction failed: ', error);});

console.log('Hey there!'); <-- "UNREACHABLE CODE DETECTED"

enter image description here

j3ff
  • 5,719
  • 8
  • 38
  • 51
FiringBlanks
  • 1,998
  • 4
  • 32
  • 48

1 Answers1

5

Your log line is immediately after a return statement. It line will never run because return leaves the function.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441