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