Type alias PickByValue<T, ValueType>

PickByValue<T, ValueType>: Pick<T, {
    [Key in keyof T]-?: T[Key] extends ValueType
        ? Key
        : never
}[keyof T]>

Given a type T, return a new type that is all the properties of T that are of type ValueType

Type Parameters

  • T

  • ValueType

Example

type Foo = { a: string; b: number; c: string };
type Bar = PickByValue<Foo, string>;
// Bar is { a: string; c: string }

Generated using TypeDoc