跳至內容

typescript/no-extra-non-null-assertion 正確性

此規則預設為開啟。

作用

禁止額外的非空斷言。

為什麼這不好?

TypeScript 中的 ! 非空斷言運算子用於斷言值的類型不包含 null 或 undefined。在單一值上多次使用該運算子不會有任何作用。

範例

ts
const foo: { bar: number } | null = null;
const bar = foo!!!.bar;

參考資料

在 MIT 授權下發布。