type null - nberlette/is GitHub Wiki
export type IsNull<T, True = true, False = false> = [T] extends [never] ? False
: [T] extends [null] ? True
: False;
Checks if the type T
is specifically null
,
returning True
if it is, and
False
if not.
T
-
True
(default:true
) -
False
(default:false
)
Types
import type { IsNull } from "@nick/is/type";
type A = IsNull<null>; // true
type B = IsNull<undefined>; // false
type C = IsNull<never>; // false
export type OmitNull<T, Deep extends boolean = false> = T extends object ? {
[K in [object Object]]: Deep extends true ? OmitNull<T[K], Deep> : T[K]
} : T;
Omit properties from an object type where the value is null
. This relies on
the IsNever
utility type.
T
-
Deep
extendsboolean
(default:false
)
Types
import type { OmitNull } from "@nick/is/type";
type A = { a: string; b: null; c: number };
type B = OmitNull<A>;
// ^? type B = { a: string; c: number }