typescript Angular 5:“void”类型的参数不分配给“{}”类型的参数 | PromiseLike<{}>'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47422142/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:03:28  来源:igfitidea点击:

Angular 5: Argument of type 'void' is not assignment to parameter of type '{} | PromiseLike<{}>'

javascriptangulartypescriptangular-promise

提问by its.david



This is my code:

这是我的代码:

public resetDefaults() {
  return new Promise ((resolve, reject) => {
    resolve(
      this.resetFilters()
    )
  }).then(()=> {return this.cachedFilters});
}

private resetFilters() {

}

The this.resetFilters()is giving me :

this.resetFilters()是给我:

Argument of type 'void' is not assignment to parameter of type '{} | PromiseLike<{}>'

“void”类型的参数不是分配给“{}”类型的参数 | PromiseLike<{}>'

I know that if I do:

我知道如果我这样做:

private resetFilters(): Promise<any> {

}

It would get rid of that error but then I have to create a new promise in that method. I just want to be able to call a function without having to add any more promises. I do need the Promise in resetDefaults()though

它会摆脱那个错误,但随后我必须在该方法中创建一个新的承诺。我只想能够调用一个函数而不必添加更多的承诺。 我确实需要的无极resetDefaults()虽然

回答by Bougarfaoui El houcine

use any:

使用any

private resetFilters() : any {

}