-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(common): strict type checking for ngtemplateoutlet (#48374)
When we create a context to inject inside our ngTemplateOutlet, the context was declare as Object, therefore, there are no compilation error. Now if we add a context, we get error at compile type. BREAKING CHANGE: If the 'ngTemplateOutletContext' is different from the context, it will result in a compile-time error. Before the change, the following template was compiling: ```typescript interface MyContext { $implicit: string; } @component({ standalone: true, imports: [NgTemplateOutlet], selector: 'person', template: ` <ng-container *ngTemplateOutlet=" myTemplateRef; context: { $implicit: 'test', xxx: 'xxx' } "></ng-container> `, }) export class PersonComponent { myTemplateRef!: TemplateRef<MyContext>; } ``` However, it does not compile now because the 'xxx' property does not exist in 'MyContext', resulting in the error: 'Type '{ $implicit: string; xxx: string; }' is not assignable to type 'MyContext'.' The solution is either: - add the 'xxx' property to 'MyContext' with the correct type or - add '$any(...)' inside the template to make the error disappear. However, adding '$any(...)' does not correct the error but only preserves the previous behavior of the code. fix #43510 PR Close #48374
- Loading branch information
1 parent
585e34b
commit d47fef7
Showing
3 changed files
with
18 additions
and
18 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