我检查了 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 operationx!
produces a value of the type ofx
withnull
andundefined
excluded. Similar to type assertions of the forms<T>x
andx
asT
, 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/