顾名思义,主要是排除变量中 null 和 undefined 的类型。
interface Item {parent: Item | null;}const fn = (item: Item) => {if (!item.parent) {return;}const _fn = () => {const p1 = item.parent.parent; // error: (item.parent)对象可能为 nullconst p2 = (<Item>item.parent).parent // ok,item.parent 整体断言const p3 =item.parent!.parent; // ok,item.parent 非空,则排除 null}}
