![](/img/trans.png)
[英]Typescript does not allow an extended class promise to be the return type of an async function
[英]Typescript async function without Promise type
当您查看 typescript async function 时,您可以清楚地看到async
和Promise<type>
的冗余。
public async test(): Promise<string> {
return "Test";
}
有没有办法配置 typecrypt 来处理没有Promise<T>
类型的异步类型? T
:
public async test(): string {
return "Test";
}
当我试图跳过Promise< >
时,我得到了这个: The return type of an async function or method must be the global Promise<T> type. Did you mean to write 'Promise<number>'?ts(1064)
The return type of an async function or method must be the global Promise<T> type. Did you mean to write 'Promise<number>'?ts(1064)
Question is about how to avoid writing boilerplate. We know that async fn() will always return a Promise, so why do I have to write Promise<T>
Question is about how to avoid writing boilerplate. We know that async fn() will always return a Promise, so why do I have to write Promise<T>
- @josh3736
TypeScript 存储库中已经有这样的建议:建议我同意评论者的意见,即这种“功能”可能会造成混淆和危险。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.