utilitypes-ts
    Preparing search index...

    Type Alias KeyOfType<T, V>

    KeyOfType: keyof {
        [K in UnionKey<T> as Normalize<T>[K] extends V ? K : never]: void
    }

    Extracts keys from T whose value types extend V.

    Type Parameters

    • T

      The target type

    • V

      The value type to match against

    type Result = KeyOfType<
    { a: string; b: number; c: string },
    string
    >;
    // ^?
    // "a" | "c"
    type A = { a: string };
    type B = { b: number };

    type Result = KeyOfType<A | B, string | undefined>;
    // ^?
    // "a"