angular - 类型“数字”不可分配给类型“布尔”
问题描述
代码:- 1. 部分:Departments[];
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'.
解决方案
如果您从错误中解释 Type 'number' is not assignable to type 'boolean'
它与sectionCount
.
正如错误所说, find() 方法必须返回一个布尔值而不是一个数字 -
尝试类似的东西 -
sectionCount = this.sections.find(x => {
return x.sections > 0;
}).sections;
推荐阅读
- performance - 有效地检查 FP 位模式是否为整数。在多种条件下更快地分支一次?
- java - Liferay Maven 服务构建器失败
- javascript - Vuetify 组件 v-text-field 没有获得类
- sql - SQL - 查询结果存储在列中
- docker - 如何退出让 docker 容器运行(在 jenkins 中)
- angular - Angular:Guards Auth Service 未按预期工作
- foreign-keys - Android Room - 依赖表中的 CASCADE 用于 DELETE 并保持不可触摸以进行 INSERT 操作?
- c++ - 警告 C4477“wprintf_s”:格式字符串“%s”需要“wchar_t *”类型的参数
- docker - gitlab-ci 运行 mariadb 服务未设置 MYSQL_ROOT_PASSWORD
- draw - 如何编写一个函数来绘制图片?我使用一些方法。但它需要改进