0
我已經寫了下面的函數功能 - 我想沒有包裝他們在一個自定義的承諾需要返回現有承諾的功能:Angular2承諾 - 返回已返回一個承諾
doAuthWithPrompt(): Promise <any> {
this.getUser() // returns promise
.then (user => {
if (user == undefined) {
this.promptForPassword() // returns promise
.then (data => {
return this.doAuth(data.email, data.password); // returns promise
})
}
else {
return this.doAuth(user.email, user.password) // returns promise
};
})
.catch (e => {return Promise.reject(false);})
}
錯誤我在我的IDE(Visual Studio代碼)我得到的是:
[TS]聲明類型既不是「無效」,也沒有「任何」必須 返回一個值的函數。
我在定義doAuthWithPrompt
時錯過了什麼?謝謝。
你需要'返回this.getUser()then..' – echonax
謝謝!爲什麼我不需要'return this.promptForPassword()'? – user1361529
@echonax爲什麼不作爲回答發佈? – 0mpurdy