“数字”类型不能分配给“布尔”类型

时间:2019-07-05 02:05:20

标签: angular

代码:- 1.部门:部门[];

let sectionCount:number;
    sectionCount = +this.sections.find(x =>x.sections).sections;

错误。

 error TS2345: Argument of type '(this: void, x: Departments) => number' is not assignable to parameter of type '(value: Departments, index: number, obj: Departments[]) => boolean'.
  Type 'number' is not assignable to type 'boolean'.

1 个答案:

答案 0 :(得分:1)

如果您是根据错误Type 'number' is not assignable to type 'boolean'进行解释,则与sectionCount无关。

如错误所述,find()方法必须返回布尔值而不是数字-

尝试类似-

sectionCount = this.sections.find(x => {
  return x.sections > 0;
}).sections;
相关问题