-11

I studied the source code of the mechanism changeDetaction in angular6 and came across an interesting design that neither I nor the guys from work know, The code here, does anyone know what it is or how it works? Specifically, line 60:

let changes: SimpleChanges = undefined !;

1 Answers1

2

If you take a look at the history of the file (e.g. blame view), you will find out how this line came into existence:

fix(core): Update types for TypeScript nullability support (#15472)

You will find the the non-null assertion operator in the TypeScript design notes which introduces

A new ! postfix expression-level operator.

It tells the compiler, that the value (and property) cannot be null. See also these related stackoverflow questions and answers:

knittl
  • 246,190
  • 53
  • 318
  • 364