Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What dose it mean using [...parent.path !] . the?

I go over the angular form module and I saw a syntax I don't recognize [...parent.path !, name];

is it typescript syntax?

it can be found at this link which is angular github code.

like image 878
ofir fridman Avatar asked Nov 24 '25 20:11

ofir fridman


1 Answers

As indicate 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
}

It indicates non-null value.

like image 137
Radonirina Maminiaina Avatar answered Nov 27 '25 12:11

Radonirina Maminiaina



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!