Type alias PickExactlyByType<T, P>

PickExactlyByType<T, P>: {
    [K in Keys<T> as If<Equals<T[K], P>, K, never>]: T[K]
}

From T, pick a set of properties whose type excatly matches P.

Type Parameters

  • T
  • P

Example

type OneLevelDeep = {
foo: boolean;
bar?: Numeric;
baz: Nullable;
fooBaz: bigint;
bazFoo: string | boolean;
seven: 7;
aNum: number;
};
type A = PickExactlyByType<OneLevelDeep, bigint>,
// A results in:
{
fooBaz: bigint;
},
// Notice how it does not pick up seven
type B = PickExactlyByType<OneLevelDeep, number>,
{
aNum: number;
}