在 JavaScript 中,变量后的叹号是什么意思?

我在一些 React/TypeScript 实现中看到过这样的例子:

ref={ ref => this.container = ref! }

这个叹号在 abc 0中是什么意思? 这是 TypeScript 中特有的东西,还是一种新的标准 JavaScript 表示法?

55485 次浏览

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.