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

add strictUnusedTemplate to template type checker #54626

Closed
sod opened this issue Feb 27, 2024 · 3 comments
Closed

add strictUnusedTemplate to template type checker #54626

sod opened this issue Feb 27, 2024 · 3 comments
Labels
area: compiler Issues related to `ngc`, Angular's template compiler compiler: extended diagnostics
Milestone

Comments

@sod
Copy link
Contributor

sod commented Feb 27, 2024

Which @angular/* package(s) are relevant/related to the feature request?

compiler

Description

referencing @angular/compiler 17.2.0

I like your addition of lint like features to your template compiler, listed on https://angular.dev/tools/cli/template-typecheck#troubleshooting-template-errors

Another warning it could throw. Unused templates:

<ng-template #foo>contents</ng-template>

If nobody accesses foo in the template or no @ViewChild('foo') annotation exists, this could be an error.

This could catch errors that happen because someone removed *ngTemplateOutlet but forgot to either remove or use the template otherwise.

@dylhunn dylhunn added the area: compiler Issues related to `ngc`, Angular's template compiler label Feb 27, 2024
@ngbot ngbot bot added this to the needsTriage milestone Feb 27, 2024
@alxhub
Copy link
Member

alxhub commented Feb 28, 2024

This is a little difficult to conceive, since it's hard to tell if the <ng-template> is used or not. It might be in the projected content of another component, where it could be queried by the name foo or simply TemplateRef. The compiler could theoretically know which content would be projected and thus subject to querying, but that's getting very nuanced. I think this is a good candidate for a lint error.

@sod
Copy link
Contributor Author

sod commented Feb 28, 2024

I thought it was possible, as my intellij IDEA grays out unused templates:
CleanShot 2024-02-28 at 12 20 08@2x

But I admit it's not 100% accurate.

I didn't even know that child components could yoink templates from projected content. That of course complicates this inspection. Will see if I suggest this at angular-eslint instead.

@sod sod closed this as completed Feb 28, 2024
@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 Mar 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: compiler Issues related to `ngc`, Angular's template compiler compiler: extended diagnostics
Projects
None yet
Development

No branches or pull requests

4 participants