Skip to content

Instantly share code, notes, and snippets.

@Misaka-0x447f
Created July 31, 2022 07:25
Show Gist options
  • Save Misaka-0x447f/d6a9a09b411502671ba98cef8a6d2794 to your computer and use it in GitHub Desktop.
Save Misaka-0x447f/d6a9a09b411502671ba98cef8a6d2794 to your computer and use it in GitHub Desktop.
// recursive magic
export type Tail<T extends any[]> = T['length'] extends 0
? never
: ((...b: T) => void) extends (a: any, ...b: infer I) => void
? I
: [];
// Type of { ...L, ...R }
// Properties in L that don't exist in R plus R
type _TypeAssignWorker<L, R> = Pick<L, Exclude<keyof L, keyof R>> & R;
type _TypeAssign<
Dest,
SourceTuple extends unknown[],
> = SourceTuple[0] extends void
? Dest
: _TypeAssign<_TypeAssignWorker<Dest, SourceTuple[0]>, Tail<SourceTuple>>;
// Type of Object.assign(Dest, ...SourceTuple)
export type TypeAssign<
DestOrMergeList,
S2 = void,
S3 = void,
S4 = void,
S5 = void,
S6 = void,
S7 = void,
S8 = void,
S9 = void,
S10 = void,
S11 = void,
S12 = void,
S13 = void,
S14 = void,
S15 = void,
S16 = void,
> = DestOrMergeList extends unknown[]
? _TypeAssign<Record<string, never>, DestOrMergeList>
: _TypeAssign<
DestOrMergeList,
[S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13, S14, S15, S16]
>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment