Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postfix double exclamation mark in TypeScript

Tags:

typescript

I know the double negation prefix, and I know TypeScript's single postfix (non-null assertion).

But what is this double postfix exclamation mark?

/.*verification code is (\d{6}).*/.exec(email.body!!)!![1]

Taken from here.

like image 720
Xiphias Avatar asked Sep 01 '26 20:09

Xiphias


1 Answers

It's similar to how !! works in JavaScript, except pointless.

! asserts that the previous expression is non-nullish.

! can be used after expressions.

expression! asserts that expression is non-nullish.

expression!! asserts that expression! is non-nullish.

A single ! suffices, but more are not syntactically prohibited. The following is valid too:

/.*verification code is (\d{6}).*/.exec(email.body!!!!!!)!!!![1]
like image 93
CertainPerformance Avatar answered Sep 04 '26 18:09

CertainPerformance



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!