梗概

  • 在变量后面加上一个!

语法

调用时的非空断言

v!.search()

  • 告诉ts编译器v不可能为空

赋值时的非空断言

let i:string
i!=null//如果没有i,ts编译器会报错:不能将null赋给string类型