Repository navigation
Description
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
unusedLetDeclarationfor 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": "_"
}
}
}
}ignorePrefixdefaults 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 inangularCompilerOptions. - 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
JeanMeche commentedon Nov 18, 2026
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.
JasinRefiku commentedon Nov 18, 2026
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 usingmarkForCheckmanually on an example such as@let _valueTick = getValueChangesSignal(valueControl)();where you might have a subscription created through a@forloop or different cases.JoostK commentedon Nov 18, 2026
This pattern seems highly suspicious to me, hinting at a design limitation elsewhere.
JeanMeche commentedon Nov 19, 2026
@JoostK I would expect this to be related to ReactiveForms not working great with OnPush.
JasinRefiku commentedon Nov 19, 2026
This.
It comes to fruit because of
valuenot being "reactive" (updating cdr wherever it's used), so on codebases that useOnPushthat 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 avalueChanges(which of course isn't 100% foul proof because ofemitEvents), and to prevent creating a subscription by yourself, we just use the template async variant.