diff --git a/source/merge-deep.d.ts b/source/merge-deep.d.ts index 31f1f3b28..7fed3b93f 100644 --- a/source/merge-deep.d.ts +++ b/source/merge-deep.d.ts @@ -63,6 +63,9 @@ type MergeDeepRecord< > = DoMergeDeepRecord, OmitIndexSignature, Options> & Merge, PickIndexSignature>; +// Helper to avoid computing ArrayTail twice. +type PickRestTypeHelper = Tail extends [] ? Type : PickRestType; + /** Pick the rest type. @@ -76,9 +79,18 @@ type Rest5 = PickRestType; // => string[] ``` */ type PickRestType = number extends Type['length'] - ? ArrayTail extends [] ? Type : PickRestType> + ? PickRestTypeHelper, Type> : []; +// Helper to avoid computing ArrayTail twice. +type OmitRestTypeHelper< + Tail extends UnknownArrayOrTuple, + Type extends UnknownArrayOrTuple, + Result extends UnknownArrayOrTuple = [], +> = Tail extends [] + ? Result + : OmitRestType]>; + /** Omit the rest type. @@ -93,7 +105,7 @@ type Tuple6 = OmitRestType; // => [] ``` */ type OmitRestType = number extends Type['length'] - ? ArrayTail extends [] ? Result : OmitRestType, [...Result, FirstArrayElement]> + ? OmitRestTypeHelper, Type, Result> : Type; // Utility to avoid picking two times the type.