Repository navigation
Description
Which @angular/* package(s) are the source of the bug?
compiler, compiler-cli
Is this a regression?
No
Description
With strictTemplates, Angular doesn't report a type error in a template arrow function when TypeScript places that error at one of the function's parameters. The template compiles, and the mistake reaches runtime.
A common case is a callback that declares a parameter the caller never passes:
@Component({
selector: 'app-root',
template: `<button (click)="retry((attempt) => load(attempt))">Retry</button>`,
})
export class App {
retry(fn: () => void) {
fn();
}
load(attempt: number) {}
}retry calls fn with no arguments, so attempt is always undefined. In a .ts file, TypeScript rejects this call:
TS2345: Argument of type '(attempt: any) => void' is not assignable to parameter of type '() => void'.
Target signature provides too few arguments. Expected 1 or more, but got 0.
In the template, Angular reports nothing. The same happens when a callback returns a function instead of a value, such as count.update((v) => () => v + 1).
TypeScript places most callback errors elsewhere, so Angular still reports them. For example, count.update((v) => String(v)) reports TS2322 at String(v).
Expected: Angular reports the error at the parameter (attempt), the same way it reports any other template type error.
Cause: the type-check code marks every arrow function parameter with a "skip diagnostics" comment (expression.ts#L386), so findSourceLocation drops every error that starts there. The marker was meant to hide implicit any errors on parameters that templates can't annotate, but shouldReportDiagnostic already filters those by error code.
Fix: the linked PR gives each parameter its source location instead of the marker. Inferred parameter types don't change. Implicit any and unused-parameter errors stay hidden.
Please provide a link to a minimal reproduction of the bug
No hosted reproduction. The snippet in the description is self-contained: paste it into any Angular 21.2+ app with strictTemplates turned on. The linked PR adds regression tests.
Please provide the exception or error you saw
None. The template compiles without errors.
Please provide the environment you discovered this bug in (run ng version)
Angular: 21.2.0 and later, including 22.2.x and 22.3.0-next.2 (main at 5d929e57e4).
Reproduced with compiler-cli tests in packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts.
Anything else?
Template arrow functions were added in 21.2.0, and the marker has been there since.
Activity
fix(compiler): report errors at arrow parameters