-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ivy): don't infer template context types when in full mode (#33537)
The Ivy template type-checker is capable of inferring the type of a structural directive (such as NgForOf<T>). Previously, this was done with fullTemplateTypeCheck: true, even if strictTemplates was false. View Engine previously did not do this inference, and so this causes breakages if the type of the template context is not what the user expected. In particular, consider the template: ```html <div *ngFor="let user of users as all"> {{user.index}} out of {{all.length}} </div> ``` As long as `users` is an array, this seems reasonable, because it appears that `all` is an alias for the `users` array. However, this is misleading. In reality, `NgForOf` is rendered with a template context that contains both a `$implicit` value (for the loop variable `user`) as well as a `ngForOf` value, which is the actual value assigned to `all`. The type of `NgForOf`'s template context is `NgForContext<T>`, which declares `ngForOf`'s type to be `NgIterable<T>`, which does not have a `length` property (due to its incorporation of the `Iterable` type). This commit stops the template type-checker from inferring template context types unless strictTemplates is set (and strictInputTypes is not disabled). Fixes #33527. PR Close #33537
- Loading branch information
Showing
2 changed files
with
52 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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