[英]functions that return promises must be async
當我在我的代碼上運行tslint時,我收到以下錯誤
functions that return promises must be async
這是代碼
private doSomething(): void {
fetch(myUrl)
.then((rsp: Response) => rsp.text()) // <-- gives error
.then(txt => this.txt = txt);
}
現在不確定如何解決這個問題因為代碼運行得很好! 有什么建議么 ?
此錯誤消息是由tslint規則promise-function-async引起的 。
您可以通過在箭頭函數表達式上添加async來遵守此規則:
.then(async (rsp: Response) => rsp.text())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.