angular - 使用 [...parent.path !] 意味着什么。这?

标签 angular typescript

我检查了 Angular 形式模块,我看到了一个我不认识的语法 [...parent.path !, name];

是 typescript 语法吗?

它可以在 this link 找到这是 Angular github 代码。

最佳答案

如指示 here .

A new ! post-fix expression operator may be used to assert that its operand is non-null and non-undefined in contexts where the type checker is unable to conclude that fact. Specifically, the operation x! produces a value of the type of x with null and undefined excluded. Similar to type assertions of the forms <T>x and x as T, the ! non-null assertion operator is simply removed in the emitted JavaScript code.

// Compiled with --strictNullChecks
function validateEntity(e?: Entity) {
    // Throw exception if e is null or invalid entity
}

function processEntity(e?: Entity) {
    validateEntity(e);
    let s = e!.name;  // Assert that e is non-null and access name
}

表示非空值。

关于angular - 使用 [...parent.path !] 意味着什么。这?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49445465/

相关文章:

javascript - 通过属性动态调用对象中的方法

html - Angular 2模型驱动形式的下拉列表

angular - TS2304 : Cannot find name 'describe' in Webpack/Angular 2

angular - 如何将 ng-template innerHTML 获取到组件

Angular:来自 json 数据的 TreeView

angular - ionic 存储在 chrome 浏览器中不起作用

Angular 8惰性路由在父级之前解析有或没有前缀和重定向

angular - 父级的 ngAfterViewInit 与子级的 ngAfterViewInit

Angular - 连接到代理服务器并获得响应,但随后显示尝试代理到 : localhost to actual server 时发生错误

angular 2/4 将 ContentChild 模板保存为字符串