javascript - 什么是异步 void 的 typedef
问题描述
与这个问题有点相关,但有所不同。
TSLint 抱怨这段代码,因为它需要一个 typedef:
private async getTranslations() {
// this.translations is a public variable used by the html
this.translations = await this._languageService.getTranslations('Foo');
}
我将其更新为
private async getTranslations() : void { ... }
这给了我错误:
type 'void' 在 ES5 中不是有效的异步函数返回,因为它不引用 pPromise 兼容的构造函数值
在不删除 async 关键字的情况下如何才能做到这一点?
解决方案
将返回类型更改为:
private async getTranslations(): Promise<void> {
this.translations = await this._languageService.getTranslations('Foo');
}
推荐阅读
- python - 无法通过 .gitignore 排除 Pipfile 和 Pipfile.lock
- r - 为什么 stargazer 会为我的 lm 回归输出提供一个输出表,但在我使用 lm_robust() 时却没有?
- postgresql - 为什么我的 postgresql 函数插入回滚?
- react-native - 使用 react-navigation 和 redux 实现身份验证流程
- haskell - 为 ADT 派生显示实例不适用于更高种类的类型族
- delphi - How to know how many tasks are already completed?
- visual-studio - 我可以在 AnkhSvn 构建中替换 TurtleTasks
- html - 将删除线元素保存到待办事项列表的本地存储
- javascript - 为什么这个 Ajax ResponseText 是空的?
- git - 为什么 Gitkraken 在大仓库中不显示任何日志?