Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Unshift T onto the arguments list of S.
- */
- type Unshift<S extends (...args: any[]) => any, T> =
- S extends (...args: infer U) => any ? (arg: T, ...args: U) => any : never;
- /**
- * Generate all the prefixes of T, not including
- * the nullary function nor T itself (unless T variadic).
- * Return types are not preserved.
- */
- type Prefixes<T extends (...args: any[]) => any> = {
- 0: () => any,
- 1: T extends (_: infer U, ...args: infer V) => any
- ? Unshift<Prefixes<(...args: V) => any>, U> | ((arg: U) => any)
- : never,
- 2: T
- }[
- T extends (arg: infer U, ...args: infer V) => any
- ? U[] extends V
- ? 2
- : V extends []
- ? 0 : 1
- : 0
- ];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement