Typescript: What a "!" at the end of attribution

I was looking through angular2 code and saw a few things, such as:

this._outlets[name] = undefined !; 

What is the meaning of this !in the end? Could not find anything on Google about this :(

+4
source share
1 answer

After some checking, I found out that it really tells the compiler that undefined is not undefined:)

If you run the compiler by means --strictNullCheckstrying to assign undefined something like string, for example, issue the following errors: Type "undefined" is not assignable to type "string". If you use undefined !, you basically bypass this check, and tsc will not give you an error.

+2
source

Source: https://habr.com/ru/post/1675906/


All Articles