在Angular中,我可能无法正确理解Promise()的概念,但我应该如何修改下面的代码,以便checkExistence()可以返回布尔值?
public checkExistence(value: string): boolean{
var exist = false;
return this.getRefData().then((rec: string[]) => {
return rec.some(el => {
el === value;
});
});
}
private async getRefData() {
return await this.configurationService.retrieveTableData().toPromise();
}
[ts] Type 'Promise<any>' is not assignable to type 'boolean'
编辑
通过执行以下操作成功地消除了上述错误:
public checkExistence(value: string): boolean{
var exist = false;
this.getRefData().then((rec: string[]) => {
return rec.some(el => {
return el === value;
});
});
}
现在的问题是函数实际上没有返回任何内容
[ts] A function whose declared type is neither 'void' nor 'any' must return a value.