Skip to main content
InterviewHubPRO
Section Overview
Q96

Question 96 of 283

Part 4: JIT vs AOT Compilation, Metadata & TypeScript (76 - 100)

34%
Angular Master (283 Qs)•Part 4: JIT vs AOT Compilation, Metadata & TypeScript (76 - 100)

What is type narrowing?

junior LevelCode ExampleTypeScript

The expression used in an ngIf directive is used to narrow type unions in the Angular template compiler similar to if expression in typescript. So *ngIf allows the typeScript compiler to infer that the data used in the binding expression will never be undefined.

javascript
@Component({
selector: 'my-component',
template: '<span *ngIf="user"> {{user.contact.email}} </span>'
})
class MyComponent {
user?: User;
}