Skip to main content

Type Alias: PickByValue<T, V>

PickByValue<T, V>: { [P in keyof T]: T[P] extends V ? P : never }[keyof T] & keyof T

Gets all the keys (as a string union) from a type T that match value V

Type Parameters

Type Parameter
T
V

Example

interface Sample {
id: string;
name: string | null;
middleName?: string;
lastName: string;
hobbies: readonly string[];
}

type BB = PickByValue<Sample, string>;
// Expected:
// "id" | "lastName"

Defined in

types.ts:148