Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(mat-tree): mat-tree reports a compilation error wher used with a trackBy option in NestedTreeControl #21364

Closed
POFerro opened this issue Dec 15, 2020 · 5 comments
Labels
area: material/tree P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@POFerro
Copy link
Contributor

POFerro commented Dec 15, 2020

Hi,

I have a mat-tree associated with the tree control:
public readonly mainMenuTreeControl = new NestedTreeControl<IMainMenuNode, string>(node => node.children, { trackBy: this.mainMenuItemTrackBy });

where this.mainMenuItemTrackBy is defined as (menuNode: IMainMenuNode): string{ ... }
when used in a view like <mat-tree [dataSource]="..." [treeControl]="mainMenuTreeControl">...</mat-tree>

compiler reports an error:
error TS2322: Type 'NestedTreeControl<IMainMenuNode, string>' is not assignable to type 'TreeControl<IMainMenuNode, IMainMenuNode>'.
31 [treeControl]="mainMenuTreeControl"

from what I have seen in code I believe MatTree should in fact be MatTree<T, K =T> as is NestedTreeControl defined and the property treeControl should also be: @Input() treeControl: TreeControl<T, K>;

Can you help me?
Thanks in advance
POFerro

@POFerro POFerro added the needs triage This issue needs to be triaged by the team label Dec 15, 2020
@crisbeto
Copy link
Member

An identical issue was reported with the framework a few days ago (angular/angular#40125), could it be the same as this one? Can you try the solution from the last comment to see if it resolves it?

@crisbeto crisbeto added area: material/tree needs: clarification The issue does not contain enough information for the team to determine if it is a real bug and removed needs triage This issue needs to be triaged by the team labels Dec 21, 2020
@POFerro
Copy link
Contributor Author

POFerro commented Dec 21, 2020

Hi @crisbeto ,

No, this case is different, I'll explain:
As of commit: #19602
TreeControl is defined as two argument generic: TreeControl<T, K = T> this change was to include the ability of having a trackBy function defined in the control itself and K is the return type of this function.

While this change happened in the TreeControl classes the class MatTree didn't change to reflect the second generic parameter so now if K != T in TreeControl class the property type in MatTree will mismatch since it is defining the property type as being TreeControl<T, T> (second generic parameter type is being inferred by default value K = T).

@crisbeto crisbeto added has pr P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed needs: clarification The issue does not contain enough information for the team to determine if it is a real bug labels Dec 23, 2020
annieyw pushed a commit that referenced this issue Jan 6, 2021
…21421)

* fix(cdk/tree): add missing generic types to trackBy Fixes (#21364)

* fix(cdk/tree): add missing generic types to trackBy Fixes (#21364)
annieyw pushed a commit that referenced this issue Jan 6, 2021
…21421)

* fix(cdk/tree): add missing generic types to trackBy Fixes (#21364)

* fix(cdk/tree): add missing generic types to trackBy Fixes (#21364)

(cherry picked from commit 22d5600)
wagnermaciel pushed a commit to wagnermaciel/components that referenced this issue Jan 14, 2021
) (angular#21421)

* fix(cdk/tree): add missing generic types to trackBy Fixes (angular#21364)

* fix(cdk/tree): add missing generic types to trackBy Fixes (angular#21364)
@rafaelss95
Copy link
Contributor

This should be closed by #21421.

@crisbeto
Copy link
Member

crisbeto commented Jan 14, 2021

Thanks for the heads-up. Closing as something that should be resolved.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: material/tree P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

No branches or pull requests

3 participants