Type alias TruthyProperties<T>

TruthyProperties<T>: Pick<T, {
    [K in Keys<T>]: IsTruthy<T[K]> extends true
        ? K
        : never
}[Keys<T>]>

Extracts truthy properties from an object type T.

Type Parameters

  • T

Example

type T = {
name: string;
age: number;
hasCar: boolean;
address?: string | null;
}
type R = TruthyProperties<T>;
// Result: { name: string; age: number; hasCar: boolean; }