Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. /**
  2. * Unshift T onto the arguments list of S.
  3. */
  4. type Unshift<S extends (...args: any[]) => any, T> =
  5. S extends (...args: infer U) => any ? (arg: T, ...args: U) => any : never;
  6.  
  7. /**
  8. * Generate all the prefixes of T, not including
  9. * the nullary function nor T itself (unless T variadic).
  10. * Return types are not preserved.
  11. */
  12. type Prefixes<T extends (...args: any[]) => any> = {
  13. 0: () => any,
  14. 1: T extends (_: infer U, ...args: infer V) => any
  15. ? Unshift<Prefixes<(...args: V) => any>, U> | ((arg: U) => any)
  16. : never,
  17. 2: T
  18. }[
  19. T extends (arg: infer U, ...args: infer V) => any
  20. ? U[] extends V
  21. ? 2
  22. : V extends []
  23. ? 0 : 1
  24. : 0
  25. ];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement