8000 Document NG0303 diagnostic when an unknown binding is present in a template · Issue #59488 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content
Document NG0303 diagnostic when an unknown binding is present in a template #59488
Closed as duplicate of#37322
@bougwal

Description

@bougwal

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

compiler

Description

Hi !

Doing large scale 'legacy' migration through SAC / CF I came over this potential optimization that might help us improve the DX slightly. Currently if a component template has NgTemplateOutlet while the respective component.imports array is missing the import of the directive, the app compiles successfully and the app might have a leaking issue that might only be caught during QA testing at runtime (supposing the respective existing component does not have properly test). I would rather expect the app to compile-time fail as it does when the aforementioned template is using something like NgClass while the respective import is missing, as this will yield NG8002 in case of missing NgClass import.


import { NgClass } from '@angular/common';
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [NgClass],
  template: `
    <!--Remove the import of NgTemplateOutlet and the compilation will succeed-->
    <ng-container *ngTemplateOutlet="ref"/>
    <ng-template #ref> <h1>can you make me fail during app compilation with NG0303 as I am compiling successfully ?</h1> </ng-template>

  <!--Remove the import of NgClass and the compilation will fail-->
  <h1 [ngClass]="show ? 'blue' : 'default'">Missing NgClass will yield NG8002 </h1>
  `,
  styles: [`
    .blue {
      color: blue; 
    }
    .default {
      color: black;
    }
  `]
})
export class AppComponent {
  title = 'repro';
  show = true; 
}

Repo: https://github.com/bougwal/NG0303

Proposed solution

I am thus, asking for:

  • The potential improvement of making NG0303 compile time failure if there are no blockers/concerns.
  • The addition of NG0303 to the error encyclopaedia, as I don't see it logged on ADEV neither under runtime nor under compile time: https://angular.dev/errors. Is there a reason to exclude it?

Let me know if I am missing smth I have to add / I look forward to the input / more context on this !

Many thanks guys !

Alternatives considered

n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: docsRelated to the documentation

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0