What does exclamation point after variable mean in JavaScript?

JavascriptTypescript

Javascript Problem Overview


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?

Javascript Solutions


Solution 1 - Javascript

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondbrrtView Question on Stackoverflow
Solution 1 - JavascriptRyan CavanaughView Answer on Stackoverflow