Safe Traversal Operator / Safe Navigator Operator

I believe that the whole point of the Safe Traversal / Navigator Operator is to take action if a variable is null or undefined. However, I receive an error that tells me that name does not exist. In order to get this code to run, I added:

task = {
  title: 'Review applications',
  assignee: {
    name: null
  }
}

Course: Angular 4: Beginner to Pro
Section: Directives (1h)
Video: 11- Safe Traversal Operator

QUESTION: Shouldn’t the code below build, even if the assignee variable is set to null?

This is the error I get:
Error:

client:159 src/app/app.component.html:3:48 - error TS2339: Property ‘name’ does not exist on type ‘never’.

3 <span *ngIf=“task.assignee”>{{ task?.assignee?.name }}

src/app/app.component.ts:5:16
5 templateUrl: ‘./app.component.html’,
Error occurs in the template of component AppComponent.

File: app.component.html

<span *ngIf="task.assignee">{{ task?.assignee?.name }}</span>

File: app.component.ts

...
task = {
  title: 'Review applications',
  assignee: null
}
...
1 Like

Thanks, @keenon !!!

1