Type alias: PickByValue<T, V>
PickByValue<
T,V>:{ [P in keyof T]: T[P] extends V ? P : never }[keyofT] & keyofT
Gets all the keys (as a string union) from a type T that match value V
Example
interface Sample {
id: string;
name: string | null;
middleName?: string;
lastName: string;
hobbies: readonly string[];
}
type BB = PickByValue<Sample, string>;
// Expected:
// "id" | "lastName"
Type parameters
| Type parameter |
|---|
T |
V |