devtypes - v2.0.0
    Preparing search index...

    Type Alias CountTrue<T, Acc>

    CountTrue: T extends readonly [
        infer H extends boolean,
        ...(infer R extends boolean[]),
    ]
        ? H extends true ? CountTrue<R, [0, ...Acc]> : CountTrue<R, Acc>
        : Acc["length"]

    Count the number of true values in a boolean tuple.

    Type Parameters

    • T extends readonly boolean[]

      Tuple of boolean values

    • Acc extends any[] = []

    Evaluates the tuple at the type level and returns a numeric literal. Useful as a building block for higher-order conditional helpers.

    type A = CountTrue< [ true, false, true ] >;  // 2
    type B = CountTrue< [ false, false ] >; // 0