Libraries
    Preparing search index...

    Type Alias ExtractBranch<Union, K>Internal

    ExtractBranch: Union extends infer B
        ? {
            [P in keyof B]-?: B[P] extends K
                ? K extends B[P] ? true : never
                : never
        }[keyof B] extends never
            ? never
            : B
        : never

    Extract the branch of a discriminated union whose discriminator property has exactly the literal type K. Works without knowing the discriminator property name by scanning all properties of each branch.

    Example:

    // Union = { type: 'assigned'; ... } | { type: 'commented'; ... }
    ExtractBranch<Union, 'assigned'> // → { type: 'assigned'; ... }

    Type Parameters

    • Union
    • K extends string