Type alias PickByType<T, P>

PickByType<T, P>: {
    [K in Keys<T> as T[K] extends P
        ? K
        : never]: T[K]
}

From T, pick a set of properties whose type are assignable to P.

Type Parameters

  • T
  • P

Example

type T = {
foo: string,
bar: bigint | boolean,
baz: number,
}
PickByType<T,true>; // Result: {}
PickByType<T,number>; // Result: { baz: number }