英文:
Type Check Failure on upgrade to PrimeNG v16 and TypeScript 5
问题
I have a PrimeNG p-tree
component that is failing on the following binding:
[(selection)]="selectedTreeNode"
selectedTreeNode
is:
selectedTreeNode: CallFlowTreeNode | null = null;
CallFlowTreeNode
extends PrimeNG's TreeNode:
export interface CallFlowTreeNode extends TreeNode {
custom?: string;
someNum?: number;
}
TreeNode
is an interface:
export interface TreeNode<T = any> { ... }
So why am I getting this?
Type 'TreeNode
| TreeNode [] | null' is not assignable to
type 'CallFlowTreeNode | null'. Type 'TreeNode[]' has no
properties in common with type 'CallFlowTreeNode'.ngtsc(2322)
What am I not seeing here with the type system?
英文:
I have a PrimeNG p-tree
component that is failing on the following binding:
[(selection)]="selectedTreeNode"
selectedTreeNode
is:
selectedTreeNode: CallFlowTreeNode | null = null;
CallFlowTreeNode
extends PrimeNG's TreeNode:
export interface CallFlowTreeNode extends TreeNode {
custom?: string;
someNum?: number;
}
TreeNode
is an interface:
export interface TreeNode<T = any> { ... }
So why am I getting this?
> Type 'TreeNode<any> | TreeNode<any>[] | null' is not assignable to
> type 'CallFlowTreeNode | null'. Type 'TreeNode<any>[]' has no
> properties in common with type 'CallFlowTreeNode'.ngtsc(2322)
What am I not seeing here with the type system?
答案1
得分: 2
错误消息显示出现了类型不匹配的问题,明确指出类型 TreeNode[]
(一个 TreeNode
数组)与 CallFlowTreeNode
接口没有共同的属性。
要解决这个问题,更新 selectedTreeNode
的类型声明为:
selectedTreeNode: CallFlowTreeNode | CallFlowTreeNode[] | null = null;
英文:
The error message you're seeing indicates a type mismatch. specifically states that the type TreeNode[]
(an array of TreeNode
) does not have properties in common with the CallFlowTreeNode
interface.
To fix the issue, update the type declaration of selectedTreeNode
to:
selectedTreeNode: CallFlowTreeNode | CallFlowTreeNode[] | null = null;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论