PokéRogue
    Preparing search index...

    Type Alias HomomorphicPick<T, Keys>

    HomomorphicPick: { [P in keyof T as Extract<P, Keys>]: T[P] }

    Works similar to the built-in Pick utility type, except for the following differences:

    • Distributes over union types and allows picking keys from any member of the union type.
    • Primitives types are returned as-is.
    • Picks all keys if Keys is any.
    • Doesn't pick number from a string index signature.

    Type Parameters

    type ImageUpload = {
    url: string;
    size: number;
    thumbnailUrl: string;
    };

    type VideoUpload = {
    url: string;
    duration: number;
    encodingFormat: string;
    };

    // Distributes over union types and allows picking keys from any member of the union type
    type MediaDisplay = HomomorphicPick<ImageUpload | VideoUpload, "url" | "size" | "duration">;
    //=> {url: string; size: number} | {url: string; duration: number}

    // Primitive types are returned as-is
    type Primitive = HomomorphicPick<string | number, 'toUpperCase' | 'toString'>;
    //=> string | number

    // Picks all keys if `Keys` is `any`
    type Any = HomomorphicPick<{a: 1; b: 2} | {c: 3}, any>;
    //=> {a: 1; b: 2} | {c: 3}

    // Doesn't pick `number` from a `string` index signature
    type IndexSignature = HomomorphicPick<{[k: string]: unknown}, number>;