Jea*_*eri 2 javascript asynchronous promise async-await tslint
当我在我的代码上运行 tslint 时,我收到以下错误
functions that return promises must be async
Run Code Online (Sandbox Code Playgroud)
这是代码
private doSomething(): void {
fetch(myUrl)
.then((rsp: Response) => rsp.text()) // <-- gives error
.then(txt => this.txt = txt);
}
Run Code Online (Sandbox Code Playgroud)
现在不知道如何解决这个问题,因为代码运行得很好!有什么建议 ?
此错误消息是由 tslint 规则promise-function-async 引起的。
您可以通过在箭头函数表达式上添加 async 来遵守此规则:
.then(async (rsp: Response) => rsp.text())