NonNullable是 TypeScript 内置的工具类型,它会从 类型T 中移除 nullundefined

    使用示例:

    //从 类型a 中移除 null和 undefined 给 b
    type a = string | null | undefined
    type b = NonNullable<a>  // b 是 string
    
    //从 类型c 中移除 null和 undefined 给 d
    type c = number | undefined
    type d = NonNullable<c>  // d 是 number
    
    //从 类型e 中移除 null和 undefined 给 f
    type e = boolean | null
    type f = NonNullable<e>  // e 是 boolean