【问题标题】:Typescript exclamation parentheses [duplicate]打字稿感叹号括号[重复]
【发布时间】:2018-03-18 00:22:38
【问题描述】:

我在the angular website看到了这个声明:

this.resolve !('hi there!');

我不知道! 在这种情况下可能意味着什么。 我遇到过non-null assertion operator,但不知何故我认为这不是这里的情况。有什么想法吗?

【问题讨论】:

    标签: angular typescript


    【解决方案1】:

    它是non-null assertion operator. 请注意this.resolve 的类型是Function|null,因此它可能为空。

    添加它是为了让编译器停止抱怨this.resolvestrictNullChecks 编译器选项打开的情况下可能为空。

    【讨论】:

    • 当然,如果他们只是删除this.arrived 标志并简单地测试this.resolve,代码会更短,并且不需要断言运算符。
    猜你喜欢
    • 2012-03-06
    • 2017-01-05
    • 2013-08-13
    • 2018-01-21
    • 2013-02-07
    • 2022-01-23
    • 2015-05-01
    • 2014-02-04
    • 1970-01-01
    相关资源
    最近更新 更多