Skip to content

feat(compiler-cli): configurable ignore prefix for the unusedLetDeclaration (NG8112) extended diagnostic #72076

Open

Description

@JasinRefiku

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

compiler-cli

Description

Templates sometimes declare a @let only for its side effect: reading a signal so an OnPush view re-renders when it changes. For example, a form control whose value is read through a typedMapper pipe needs the view to re-render on valueChanges:

@let _valueTick = getValueChangesSignal(valueControl)();

_valueTick is never read, so NG8112 reports it on every build. The warning is correct about the read, but the declaration is intentional. An unused @let expression is still evaluated on every template update, which is exactly why it works as a dependency.

Today there are only two options:

  • Suppress unusedLetDeclaration for the whole project, which also hides genuinely dead @lets.
  • Move the read into a component method that calls the signal and returns the value. That works, but it puts template-only plumbing into the class, and the warning gives no hint that the original was intentional.

TypeScript (noUnusedLocals/noUnusedParameters) and ESLint (no-unused-vars with varsIgnorePattern) both let a naming convention mark a binding as intentionally unused. NG8112 has no equivalent.

Proposed solution

Let a check's entry in extendedDiagnostics.checks take an object as well as a category string. For unusedLetDeclaration, that object would add an ignorePrefix option:

"angularCompilerOptions": {
  "extendedDiagnostics": {
    "checks": {
      "unusedLetDeclaration": {
        "category": "warning",
        "ignorePrefix": "_"
      }
    }
  }
}
  • ignorePrefix defaults to unset, so the diagnostic behaves exactly as today unless a project opts in.
  • The existing string form ("unusedLetDeclaration": "warning") stays valid.
  • In UnusedLetDeclarationCheck.run(), a declaration is skipped when its name starts with the configured prefix:
if (!usedLetDeclarations.has(decl) && !(ignorePrefix && decl.name.startsWith(ignorePrefix))) {

We've been running the hard-coded _ version of this as a local patch on 22.2.4. It suppresses only the intentional declarations, and every other unused @let is still reported.

Alternatives considered

  • Hard-code _ as the ignore prefix (no config). Simpler, and it matches TypeScript, but it changes behaviour for projects that already use _-prefixed @lets and expect the warning.
  • A regex option, like ESLint's varsIgnorePattern. More flexible, but a prefix covers the real use case and is easier to validate in angularCompilerOptions.
  • Suppress the check per project. Loses the diagnostic for real dead code.
  • A template-level opt-out comment. Noisier than a naming convention, and there's no precedent for one in Angular templates.

Activity

  1. added
    area: compiler
    on Nov 17, 2026
  2. added this to the needsTriage milestone on Nov 17, 2026
  3. added
    open for contributions
    on Nov 18, 2026
  4. JeanMeche commented on Nov 18, 2026

    @JeanMeche
    Member

    I think the request is reasonable, but we shouldn't even have an option for it. The compiler should'nt yell at you for something that is a common patterm (_ prefixed variables).

    On the other hand that code could be an effect + markForCheck.

  5. JasinRefiku commented on Nov 18, 2026

    @JasinRefiku
    Author

    I think the request is reasonable, but we shouldn't even have an option for it. The compiler should'nt yell at you for something that is a common patterm (_ prefixed variables).

    On the other hand that code could be an effect + markForCheck.

    Indeed - as noted that it could very well be done through a markForCheck, just decided to file this as it's a nice to have to prevent using markForCheck manually on an example such as @let _valueTick = getValueChangesSignal(valueControl)(); where you might have a subscription created through a @for loop or different cases.

  6. JoostK commented on Nov 18, 2026

    @JoostK
    Member

    This pattern seems highly suspicious to me, hinting at a design limitation elsewhere.

  7. JeanMeche commented on Nov 19, 2026

    @JeanMeche
    Member

    @JoostK I would expect this to be related to ReactiveForms not working great with OnPush.

  8. JasinRefiku commented on Nov 19, 2026

    @JasinRefiku
    Author

    @JoostK I would expect this to be related to ReactiveForms not working great with OnPush.

    This.

    It comes to fruit because of value not being "reactive" (updating cdr wherever it's used), so on codebases that use OnPush that still haven't updated to signal forms, this is pretty common when components are nested - so one of the common fixes to this is using a valueChanges (which of course isn't 100% foul proof because of emitEvents), and to prevent creating a subscription by yourself, we just use the template async variant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: compileropen for contributions

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions