-
-
Notifications
You must be signed in to change notification settings - Fork 0
type undefined
Nicholas Berlette edited this page Jun 19, 2025
·
1 revision
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>; // falseexport 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-
Deepextendsboolean(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 }