Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the "!" operator do to the right of a variable in TypeScript? [duplicate]

Tags:

typescript

e.g. a += b! - c!; I saw several expressions like this but I can't find what it's called or what it does

like image 401
Moisés Icaza Avatar asked Sep 14 '25 09:09

Moisés Icaza


1 Answers

you're telling the compiler that even though judging purely by the code, the variable could be undefined, you, the programmer, know for 100% sure that it will have a value, so you're not going to do a check to see if it has a value or not.

See playground example

like image 89
Bart van den Burg Avatar answered Sep 17 '25 02:09

Bart van den Burg