繁体   English   中英

返回promises的函数必须是异步的

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM