打字稿:'!'的含义是什么?在归因结束时

时间:2017-04-28 11:33:35

标签: typescript

我正在查看angular2代码并看到了一些内容,例如:

this._outlets[name] = undefined !; 

最后!的含义是什么?无法在谷歌上找到任何关于它的内容:(

2 个答案:

答案 0 :(得分:2)

经过一些检查后,我发现它确实告诉编译器undefined is not undefined:)

如果您使用--strictNullChecks运行编译器尝试将undefined分配给某个字符串,例如字符串,则会出现以下错误:Type "undefined" is not assignable to type "string"。如果你使用undefined !,你基本上绕过了这个检查,tsc不会给你一个错误。

答案 1 :(得分:0)

此后修复表达式运算符 ! 可用于断言其操作数在运行时不能为 nullundefined