Type Check Failure on upgrade to PrimeNG v16 and TypeScript 5.

huangapple go评论74阅读模式
英文:

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)]=&quot;selectedTreeNode&quot;

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&lt;T = any&gt; { ... }

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; 

huangapple
  • 本文由 发表于 2023年5月22日 18:12:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76305126.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定