mirror of
https://github.com/angular/angular.git
synced 2026-11-23 07:05:14 -05:00
When generating type check blocks for `@for` loops, a non-null assertion is appended to the collection expression. If the collection expression is a compound expression (e.g. binary or logical operations like a && b), the lack of outer parentheses caused the ! to bind only to the rightmost operand (a && b!), leading to typecheck errors such as TS2532.
This wraps the expression via .wrapForTypeChecker() before appending !.
Template type checking for compound expressions in `@for` loops may surface new type errors
Template type checking for `@for` loops now more accurately checks the entire collection expression when compound expressions (such as `(x | async) || []` or logical/ternary operations) are used.
Previously, certain invalid expressions in `@for` loops could slip through template type checking unnoticed. As a result, you may see new TypeScript diagnostics (such as `TS2488: Type '{}' must have a '[Symbol.iterator]()' method that returns an iterator`) if the expression does not evaluate to an iterable type. For example, when a component property `x` is typed as `any`, `(x | async)` produces `unknown | null`, which causes `(x | async) || []` to type check as `{}` rather than an iterable array.
To fix these errors, ensure that values referenced in the template are strongly typed on the component class (for example, declaring `x: Observable<Item[]>` instead of `any`), or use `$any(...)` in the template (for example, `$any(x | async) || []`).