NullishPropertiesOf<T>: {
    [P in keyof T]-?: undefined extends T[P]
        ? P
        : null extends T[P]
            ? P
            : never
}[keyof T]

Returns all shallow properties that accept undefined or null. Does not include Optional properties, only undefined or null.

Type Parameters

  • T

Example

type UndefinedProps = NullishPropertiesOf<{
id: number | undefined,
createdAt: string | undefined,
firstName: string | null, // nullable properties are included
lastName?: string, // optional properties are not included.
}>;

// is equal to

type UndefinedProps = 'id' | 'createdAt' | 'firstName';