What does exclamation point after variable mean in JavaScript? [duplicate]
I've seen in some React/TypeScript implementations such as :
ref={ ref => this.container = ref! }
What does the exclamation point means in ref!
?
Is that something specific in TypeScript, or a new standard JavaScript notation?
Solution 1:
In TypeScript, a postfix !
removes null
and undefined
from the type of an expression.
This is useful when you know, for reasons outside TypeScript's inference ability, that a variable that "could" be null
or undefined
actually isn't.