5

I've come across this statement on the angular website:

this.resolve !('hi there!');

I have no idea what the ! might mean in this context. I've come across the non-null assertion operator but I somehow don't think that's what it is here. Any idea?

Renaud
  • 4,569
  • 7
  • 41
  • 72

1 Answers1

3

It is the non-null assertion operator. Note that the type for this.resolve is Function|null so it can possibly be null.

It is added so that the compiler stops complaining about this.resolve being possibly null with strictNullChecks compiler option turned on.

Saravana
  • 37,852
  • 18
  • 100
  • 108
  • Of course if they just dropped the `this.arrived` flag and simply tested `this.resolve` the code would be shorter and wouldn't need the assertion operator. – Duncan Oct 06 '17 at 09:13