外觀
禁止在可選鏈表達式後使用非空斷言。
如果物件為 null 或 undefined,?. 可選鏈表達式會提供 undefined。使用 ! 非空斷言來斷言 ?. 可選鏈表達式的結果為非可為 null 的,這很可能是錯誤的。
?.
!
大多數情況下,物件要么不是可為 null 的,不需要為其屬性查詢使用 ?.,要么 ! 是不正確的,引入了類型安全漏洞。
foo?.bar!; foo?.bar()!;