Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: MergeDeep for typescript 5.4 #807

Merged
merged 5 commits into from
Jan 30, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions source/merge-deep.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ type MergeDeepRecord<
> = DoMergeDeepRecord<OmitIndexSignature<Destination>, OmitIndexSignature<Source>, Options>
& Merge<PickIndexSignature<Destination>, PickIndexSignature<Source>>;

// Utility to avoid computing ArrayTail twice.
type PickRestType___<Tail extends UnknownArrayOrTuple, Type> = Tail extends [] ? Type : PickRestType<Tail>;

/**
Pick the rest type.

Expand All @@ -76,9 +79,12 @@ type Rest5 = PickRestType<string[]>; // => string[]
```
*/
type PickRestType<Type extends UnknownArrayOrTuple> = number extends Type['length']
? ArrayTail<Type> extends [] ? Type : PickRestType<ArrayTail<Type>>
? PickRestType___<ArrayTail<Type>, Type>
: [];

// Utility to avoid computing ArrayTail twice.
type OmitRestType___<Tail extends UnknownArrayOrTuple, Type extends UnknownArrayOrTuple, Result extends UnknownArrayOrTuple = []> = Tail extends [] ? Result : OmitRestType<Tail, [...Result, FirstArrayElement<Type>]>;
sindresorhus marked this conversation as resolved.
Show resolved Hide resolved

/**
Omit the rest type.

Expand All @@ -93,7 +99,7 @@ type Tuple6 = OmitRestType<string[]>; // => []
```
*/
type OmitRestType<Type extends UnknownArrayOrTuple, Result extends UnknownArrayOrTuple = []> = number extends Type['length']
? ArrayTail<Type> extends [] ? Result : OmitRestType<ArrayTail<Type>, [...Result, FirstArrayElement<Type>]>
? OmitRestType___<ArrayTail<Type>, Type, Result>
: Type;

// Utility to avoid picking two times the type.
Expand Down