src/main/webapp/app/plan-board/plan-board.component.html:75:39 - error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. Type 'undefined' is not assignable to type 'number'. 75 [nzChecked]="setOfCheckedId.has(planOrder.item!.id)" ~~~~~~~~~~~~~~~~~~ src/main/webapp/app/plan-board/plan-board.component.ts:42:16 42 templateUrl: './plan-board.component.html', ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component PlanBoardComponent.
时间: 2023-07-09 12:54:27 浏览: 59
这个错误提示是 TypeScript 的类型检查器报出来的,意思是 `setOfCheckedId.has()` 方法的参数类型应该是 `number`,但是 `planOrder.item!.id` 表达式的类型是 `number | undefined`,所以不能直接传递给 `setOfCheckedId.has()` 方法。你可以在这个表达式后面添加一个 `!` 来表示这个值一定不是 `undefined`,这样就可以解决这个问题了。修改后的代码如下所示:
```
[nzChecked]="setOfCheckedId.has(planOrder.item!.id!)"
```
或者你也可以先将 `planOrder.item!.id` 提取到一个变量中,再将变量传递给 `setOfCheckedId.has()` 方法:
```
<ng-container *ngFor="let planOrder of planOrders">
<nz-checkbox [nzChecked]="setOfCheckedId.has(getItemId(planOrder))" (nzCheckedChange)="onItemChecked(planOrder, $event)">
</nz-checkbox>
</ng-container>
...
getItemId(planOrder: IPlanOrder): number {
return planOrder.item?.id!;
}
```
这样就可以避免这个类型错误了。
相关问题
./src/main/webapp/app/app.constants.ts - Error: Module parse failed: parser.destructuringAssignmentPropertiesFor is not a function怎么解决
这种错误通常是因为你的代码在编译或解析过程中遇到了语法错误或格式不规范的代码。对于这个特定的错误,建议检查你的代码中是否使用了不支持的语法或语言元素,同时检查你的编译器版本是否与你项目所需的版本相匹配。你也可以尝试更新你的编译器或重装它以解决这个问题。如果以上方法都无效,你可以在相关开发社区中提问寻求帮助。
src/main/webapp/app/plan-board/plan-board.component.html:75:49 - error TS2551: Property 'itemId' does not exist on type 'IPlanOrder'. Did you mean 'item'? 75 [nzChecked]="setOfCheckedId.has(planOrder.itemId)" ~~~~~~ src/main/webapp/app/plan-board/plan-board.component.ts:42:16 42 templateUrl: './plan-board.component.html', ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component PlanBoardComponent.
这个错误提示是 TypeScript 的类型检查器报出来的,意思是 `IPlanOrder` 类型上没有 `itemId` 属性,但是在 `plan-board.component.html` 模板文件的第 75 行中却使用了这个属性。检查一下 `IPlanOrder` 的定义,看看是否应该将 `itemId` 改成 `item`。或者你可以在 `plan-board.component.ts` 文件中声明 `itemId` 属性,或者使用 `item.id` 替代 `itemId`,这样就能避免这个错误了。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)