如题,看到源码中有
function addId(id: string) {
const { identifiers } = context
if (identifiers[id] === undefined) {
identifiers[id] = 0
}
identifiers[id]!++
}
function removeId(id: string) {
context.identifiers[id]!--
}
分开来好理解,
!强制解析,递增递减。
但不知道是否是合起来理解。
!
是断言,因为根据 ts 类型推导identifiers[id]
可能为空,而!
是一个 NonNullAssert,写上这个表示identifiers[id]
肯定不为空,可以安全的做自增运算。