Using Angulars Non Null Assertion Operator | Task

Ole Ersoy
May - 04  -  1 min

Scenario

We have a decorated property like this in our component:

@ViewChild(MatSort, { static: false }) sort: MatSort;

And this produces the lint error:

MatSort Property 'sort' has no initializer and is not definitely assigned in the constructor.ts(2564)

Approach

Use Angular's non null assertion operator !.

@ViewChild(MatSort, { static: false }) sort!: MatSort;