10000 Compiler should error on unknown structural directives · Issue #37322 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

Compiler should error on unknown structural directives #37322

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

Closed
nexsandro opened this issue May 28, 2020 · 13 comments
Closed

Compiler should error on unknown structural directives #37322

nexsandro opened this issue May 28, 2020 · 13 comments
Labels
area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime core: directive matching core: ng-template and *microsyntax cross-cutting: types P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent state: confirmed
Milestone

Comments

@nexsandro
Copy link
nexsandro commented May 28, 2020

Issue an warning when compiling a template that do not match an structural directive selector.

Relevant Package

This feature request is for @angular/core

Description

The compiler completely ignore an selector like *myStructuralDirective without warning if it do not match any directive. This turns difficult to see that we are doing something wrong.

Describe the solution you'd like

If the selector in the template for an structural directive do not match any directive, show an warning about possible wrong usage.

Describe alternatives you've considered

I don't see alternatives.

@pkozlowski-opensource pkozlowski-opensource added area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime core: directive matching core: ng-template and *microsyntax labels May 28, 2020
@ngbot ngbot bot added this to the needsTriage milestone May 28, 2020
@JoostK JoostK added feature Issue that requests a new feature and removed type: bug/fix labels Jul 4, 2020
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Jul 4, 2020
@jelbourn jelbourn changed the title need warning when not matching the structural directive selector Compiler should error on unknown structural directives Jan 13, 2021
@jelbourn jelbourn removed the feature Issue that requests a new feature label Jan 13, 2021
@ngbot ngbot bot modified the milestones: Backlog, needsTriage Jan 13, 2021
@jelbourn jelbourn added the P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent label Jan 13, 2021
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Jan 13, 2021
@jelbourn
Copy link
Member

Changing this from a feature request to a bug. Also removing the breaking changes label because this would have been an error at run-time already.

@alxhub
Copy link
Member
alxhub commented Jul 9, 2021

Interestingly, <p *foo="'bar'"> is a runtime error, but <p *foo> is not.

@tfalvo
Copy link
tfalvo commented Jan 27, 2022

Please, is is possible to extend this issue to any attribute directive ?

Found this comment : #40664 (comment), which says that was a duplicated issue with this one.
But it's not just dealing about structural directive.

For example:
<button mat-button>ok</button>

No compiler error, even with strictTemplates, if MatButtonModule is not imported.
(or any local directive declared).
It would be very interesting and powerful if compiler would be able to check this.

@yhaiovyi-tripactions
Copy link

Om my god, it's still opened? These issues make any refactoring unbearable and extremely risky. And yet Angular team decided to focus on bells and whistles instead. Well good luck.

@livanov
Copy link
livanov commented Feb 7, 2024

Stopping by to "revive" the issue. Still facing up this problem in 2024 with Angular 15.

@szollbrecht
Copy link

Stopping by to "revive" the issue. Still facing up this problem in 2024 with Angular 15.

Still valid for Angular 17.

@TobyBladen
Copy link

Are there any updates on this issue? I am still facing this problem where unknown structural directives are not detected at compile time. It just manifests as an error in the console at runtime. It certainly makes refactoring much riskier than it ought to be.

@jeandat
Copy link
jeandat commented Oct 11, 2024

Same here with angular 18. This is a big problem for big applications with thousands of components. We can't retest every single view for every use cases of the app. The compiler must catch this. If it's not, please make this a top priority 🙏.

@manbearwiz
Copy link
Contributor
manbearwiz commented Jan 8, 2025

Running into this when refactoring into standalone components. We do have extended diagnostics that will detect if known control flow directives imports are missing but not custom ones. The diagnostic that detects unused structural directive imports in component definitions does work on custom directives. Is this something you would accept a PR on?

@JeanMeche
Copy link
Member

Note: The new extended diagnostic will be shipped in 19.2 (scheduled for 2nd half of Febuary)

PrajaktaB27 pushed a commit to PrajaktaB27/angular that referenced this issue Feb 7, 2025
…lar#59443)

Adds a new diagnostic that ensures that a standalone component using custom structural directives in a template has the necessary imports for those directives.

Fixes angular#37322

PR Close angular#59443
@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 15, 2025
manbearwiz added a commit to manbearwiz/angular that referenced this issue Mar 26, 2025
Adds a new diagnostic that ensures that a standalone component using custom structural directives in a template has the necessary imports for those directives.

Fixes angular#37322
JeanMeche pushed a commit to manbearwiz/angular that referenced this issue Apr 25, 2025
Adds a new diagnostic that ensures that a standalone component using custom structural directives in a template has the necessary imports for those directives.

Fixes angular#37322
mmalerba pushed a commit that referenced this issue Apr 29, 2025
Adds a new diagnostic that ensures that a standalone component using custom structural directives in a template has the necessary imports for those directives.

Fixes #37322

PR Close #59443
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 area: core Issues related to the framework runtime core: directive matching core: ng-template and *microsyntax cross-cutting: types P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent state: confirmed
Projects
None yet
Development

No branches or pull requests

0