Repository navigation
fix(compiler): report errors at arrow parameters - #71734
Merged
thePunderWoman merged 3 commits intoNov 9, 2026
Merged
Conversation
Template type checking dropped every TypeScript diagnostic that started at an arrow function parameter. For example, with a component method `takes(fn: (x: number) => number)`, the template expression `takes((value) => () => 1)` compiled without the TS2345 error that TypeScript reports at `value`. The type-check block marked each arrow function parameter with an ignore comment to hide implicit `any` errors, which template authors can't fix by adding a type. The marker hid all diagnostics that start at the parameter. Implicit `any` and unused-declaration errors are already filtered by error code, so parameters now carry their source span instead, and other errors are reported at the parameter. The parser left the expression offset out of arrow function parameter spans, so inside interpolations the spans started too early. The spans are now correct. As a side effect, go-to-definition on a parameter reference returns the parameter instead of the enclosing expression. Fixes angular#71733
crisbeto
reviewed
Oct 29, 2026
Flarette
force-pushed
the
fix/template-arrow-param-diagnostics
branch
from
October 30, 2026 09:32
e0420ba to
8c7f40e
Compare
crisbeto
reviewed
Oct 30, 2026
crisbeto
approved these changes
Nov 3, 2026
Member
|
Passing TGP, except for one app that needs to be cleaned up first. |
Member
|
Internal app is cleaned up, this should be good to go. |
Member
|
Caretaker note: the presubmit is behaving weirdly for some reason. This passes TGP so it should be good to go. |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #71733
Why the change
Under
strictTemplates, a TypeScript error that starts at a template arrow function parameter, such as a callback that declares a parameter its caller never passes, is silently dropped; with this fix Angular reports it at the parameter.Special things to note
should ignore diagnostics on arrow function parameters, which asserted theD:ignoremarker. The marker's only purpose was hiding implicitanyerrors, and those stay hidden. See Why the oldD:ignorespec changes.{{…}}they started too early ({(valinstead ofval, and further off in later interpolations). This PR fixes that too. Event bindings have no offset, so they weren't affected.(a, a) => anow reports TS2300 at bothas. Language service: go-to-definition on an arrow parameter reference now returns the parameter (val) instead of the enclosing expression (val + 1).Change outline
The template from the issue:
What the type-check block emits for the arrow function. Other location comments are left out:
How the TS2345 error, which starts at
attempt, is mapped back to the template:Parameter locations from the parser, for
{{a}} {{(foo, bar) => foo + bar}}:Why the old
D:ignorespec changestype_check_block_spec.tshadshould ignore diagnostics on arrow function parameters, which expected(a /*D:ignore*/, b /*D:ignore*/) =>. It came from 87a4223 (#66294), the commit that added template arrow functions. The commit message and the PR don't discuss the marker. The one stated reason is the code comment that commit put on it:Both goals still hold without the marker:
anyerror (TS7006) on parameters that templates can't annotateshouldReportDiagnosticdrops TS7006 everywhere in the type-check block. It has done so since 2019 (#33125), before arrow functions existed. Template arrow parameters can only be plain names, so TS7006 is the only implicitanyerror they can produce.should not report implicit any errors on arrow functions defined in @let(existing, from the same commit, unchanged),should not report implicit any errors on arrow functions without a contextual type(new)anyshould infer the types of parameters of arrow functions passed in as callbacks(existing, unchanged),should not report errors on contextually typed arrow function parameters(new)shouldReportDiagnosticdrops both codes.should not report unused arrow function parameters(new, intypecheck/test/diagnostics_spec.ts, withnoUnusedLocalsandnoUnusedParameters)The marker also hid every other error that starts at a parameter, which is the bug this PR fixes. The rewritten spec,
should add span info to arrow function parameters, now expects(a /*3,4*/, b /*6,7*/) =>.Changed files:
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
A template type error is not reported when TypeScript places it at an arrow function parameter. Examples are a callback with more parameters than its caller passes, a callback that returns a function instead of a value, and duplicate parameter names.
Issue Number: #71733
What is the new behavior?
The error is reported at the parameter. Implicit
anyand unused-parameter errors on template arrow functions are still not reported.Does this PR introduce a breaking change?
Apps that contain such an error will now fail to compile under
strictTemplates. The error was always there, but Angular didn't report it.Other information
The duplicate-name and unused-parameter specs are in
typecheck/test/diagnostics_spec.tsrather than the ngtsc suite. Under the preprocessor backend (ngtsc_ngp), the compiled component code is type-checked as well, and its copy of the arrow function produces its ownDuplicate identifierand TS6133 errors without a template location. That happens with and without this PR.diagnostics_spec.tschecks only the type-check block, so these specs pass on both backends.Template arrow functions were added in 21.2.0, so 22.2.x has this bug too. This is a candidate for the patch branch. #52322 is a precedent: it surfaced comparison errors that an ignore marker hid, landed as a plain fix, and was cherry-picked to the release branch.