0

I have just come across

this.person!.name

in my codebase, previously I have seen this.person?.name which is optional chaining, but I have never seen ! be used nor can I find any resource to explain it's use, can anyone shed any light on it?

Udders
  • 6,914
  • 24
  • 102
  • 194
  • 1
    It means that according to Typescript, `this.person` can be null or undefined, but the developer who coded this know that in this specific case, the value can't be null or undefined, so he added `!` to remove the warning about nullability – AoooR Nov 03 '22 at 15:52
  • It's slightly worrying that you tagged this [tag:typescript] code in *your codebase* as [tag:javascript]. – Quentin Nov 03 '22 at 15:53

0 Answers0