初探mobx-react-lite
react hook
ts变量后面感叹号
官方文档上的一个例子很好的说明了这个问题
interface Entity {
name: string
}
// 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
}
如果直接使用let s = e.name;,编译器会抛出e可能不存在的错误,但是使用非空断言,则表示e肯定是存在的,从而不会产生编译问题。