Search code examples
angulartypescriptprimeng

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?


Solution

  • 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;