
NgIf
context variables in template type checker (#36627)
When the `NgIf` directive is used in a template, its context variables can be used to capture the bound value. This is sometimes used in complex expressions, where the resulting value is captured in a context variable. There's two syntax forms available: 1. Binding to `NgIfContext.ngIf` using the `as` syntax: ```html <span *ngIf="enabled && user as u">{{u.name}}</span> ``` 2. Binding to `NgIfContext.$implicit` using the `let` syntax: ```html <span *ngIf="enabled && user; let u">{{u.name}}</span> ``` Because of the semantics of `ngIf`, it is known that the captured context variable is truthy, however the template type checker would not consider them as such and still report errors when `strict` is enabled. This commit updates `NgIf`'s context guard to make the types of the context variables truthy, avoiding the issue. Based on https://github.com/angular/angular/pull/35125 PR Close #36627
Angular
Angular es una plataforma de desarrollo para construir aplicaciones web y móviles que usa TypeScript/JavaScript y otros lenguajes de programación.
Guía rápida
Comienza a usarlo en 5 minutos.
Registro de cambios (Changelog)
¿Quieres ayudar?
¿Quieres encontrar fallos, colaborar con código, o mejorar la documentación? ¡Excelente! Lee nuestras pautas para colaborar y luego revisa algunos de nuestras incidencias (issues) en ayuda comunitaria.
Description
Languages
TypeScript
86.3%
JavaScript
8.5%
HTML
1.8%
Starlark
1.7%
CSS
1%
Other
0.6%