admin管理员组文章数量:1434900
Here is my code:
async buildSomething(): any {
const requestData = await request;
requestData.forEach(i => this.table.push(i));
}
How I should type a void function, because it does something but It does not return anything.
In my case I used any but tslint shows me this:
Type 'any' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-patible constructor value.
How should I achieve this?
Here is my code:
async buildSomething(): any {
const requestData = await request;
requestData.forEach(i => this.table.push(i));
}
How I should type a void function, because it does something but It does not return anything.
In my case I used any but tslint shows me this:
Type 'any' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-patible constructor value.
How should I achieve this?
Share Improve this question asked Oct 28, 2020 at 14:22 Amos Isaila Lucian OnofreiAmos Isaila Lucian Onofrei 3263 silver badges17 bronze badges 3- is this unclear? why people put -1? dude, I just need some advice, thats all – Amos Isaila Lucian Onofrei Commented Oct 28, 2020 at 14:26
-
Have you tried typing it as
void
? – Heretic Monkey Commented Oct 28, 2020 at 14:28 - yup, the same tslint message – Amos Isaila Lucian Onofrei Commented Oct 28, 2020 at 14:40
2 Answers
Reset to default 4All async functions return something: they return promises. So you don't want void
, you want Promise<void>
async buildSomething(): Promise<void> {
const requestData = await request;
requestData.forEach(i => this.table.push(i));
}
The return type should be Promise<void>
本文标签: javascriptHow to type async function in TypeScript when its a void functionStack Overflow
版权声明:本文标题:javascript - How to type async function in TypeScript when its a void function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745641971a2667910.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论