【发布时间】:2018-03-18 00:22:38
【问题描述】:
我在the angular website看到了这个声明:
this.resolve !('hi there!');
我不知道! 在这种情况下可能意味着什么。
我遇到过non-null assertion operator,但不知何故我认为这不是这里的情况。有什么想法吗?
【问题讨论】:
标签: angular typescript
我在the angular website看到了这个声明:
this.resolve !('hi there!');
我不知道! 在这种情况下可能意味着什么。
我遇到过non-null assertion operator,但不知何故我认为这不是这里的情况。有什么想法吗?
【问题讨论】:
标签: angular typescript
它是non-null assertion operator. 请注意this.resolve 的类型是Function|null,因此它可能为空。
添加它是为了让编译器停止抱怨this.resolve 在strictNullChecks 编译器选项打开的情况下可能为空。
【讨论】:
this.arrived 标志并简单地测试this.resolve,代码会更短,并且不需要断言运算符。