简体   繁体   English

错误在nodejs中缺少函数的返回类型

[英]error Missing return type on function in nodejs

I have this function, but when compiling the app.我有这个功能,但是在编译应用程序时。

public async test(options?: { engine?: Config }): Promise<any> {
        const hostel = new Service({
            list: this.servicesList,
            createService: list => this.dbService.buildService(list)
        });
     return hostel.load();
    }

I have this error:我有这个错误:

26:27  error  Missing return type on function                             
@typescript-eslint/explicit-function-return-type.

on this line createService: list => this.dbService.buildService(list) text**在这一行createService: list => this.dbService.buildService(list) text**

As mentioned by Andrew in the comments, you are not returning anything from the function.正如安德鲁在评论中提到的,你没有从函数中返回任何东西。 If that's what you expect, just change Promise<any> to Promise<void>如果那是您的期望,只需将Promise<any>更改为Promise<void>

You only should add return in the function您只应该在函数中添加 return

public async test(options?: { engine?: Config }): Promise<any> {
   const hostel = new Service({
      list: this.servicesList,
      createService: list => this.dbService.buildService(list)
   });
   return hostel;// Missing line
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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