交易后检测到无法访问的代码

时间:2018-02-18 20:49:44

标签: javascript angular firebase google-cloud-firestore unreachable-code

我收到警告'检测到无法访问的代码'在我的打字稿文件中。运行Firebase事务后无效。这是交易代码:

  //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"

Image

1 个答案:

答案 0 :(得分:1)

您的日志行紧接在return语句之后。它将永远不会运行,因为return离开了函数。