-
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): avoid duplicate errors in safe navigations and template gua…
…rds (#34417) The template type checker generates TypeScript expressions for any expression that occurs in a template, so that TypeScript can check it and produce errors. Some expressions as they occur in a template may be translated into TypeScript code multiple times, for instance a binding to a directive input that has a template guard. One example would be the `NgIf` directive, which has a template guard to narrow the type in the template as appropriate. Given the following template: ```typescript @component({ template: '<div *ngIf="person">{{ person.name }}</div>' }) class AppComponent { person?: { name: string }; } ``` A type check block (TCB) with roughly the following structure is created: ```typescript function tcb(ctx: AppComponent) { const t1 = NgIf.ngTypeCtor({ ngIf: ctx.person }); if (ctx.person) { "" + ctx.person.name; } } ``` Notice how the `*ngIf="person"` binding is present twice: once in the type constructor call and once in the `if` guard. As such, TypeScript will check both instances and would produce duplicate errors, if any were found. Another instance is when the safe navigation operator is used, where an expression such as `person?.name` is emitted into the TCB as `person != null ? person!.name : undefined`. As can be seen, the left-hand side expression `person` occurs twice in the TCB. This commit adds the ability to insert markers into the TCB that indicate that any errors within the expression should be ignored. This is similar to `@ts-ignore`, however it can be applied more granularly. PR Close #34417
- Loading branch information
Showing
5 changed files
with
111 additions
and
29 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
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
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