bupkis
    Preparing search index...

    Type Alias MutableOrReadonly<Tuple>

    MutableOrReadonly: Tuple extends readonly (infer Item)[]
        ? Item[] | readonly Item[]
        : Tuple extends readonly [infer First, ...(infer Rest)]
            ? [First, ...Rest] | readonly [First, ...Rest]
            : Tuple

    Makes tuple types accept both mutable and readonly variants.

    This utility type creates a union of both mutable and readonly versions of a tuple type, providing flexibility for function parameters that should accept either variant. This is particularly useful for assertion function parameters where users may pass either const arrays (readonly) or regular arrays.

    The type handles both array types and specific tuple types, creating appropriate unions for each case to maintain type safety while maximizing usability.

    Type Parameters

    • Tuple extends readonly unknown[]

      The readonly tuple type to make flexible

    type FlexibleArgs = MutableOrReadonly<readonly [string, number]>;
    // Results in: [string, number] | readonly [string, number]

    function acceptArgs(args: FlexibleArgs) { ... }
    acceptArgs(['hello', 42]); // ✓ mutable array
    acceptArgs(['hello', 42] as const); // ✓ readonly array

    ExpectFunction and ExpectAsyncFunction which use this for parameter flexibility