aboutsummaryrefslogtreecommitdiff
path: root/src/definitions/utils.ts
blob: 03764c1dfeb49238749b685835e706ed6a078455 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
// https://stackoverflow.com/a/53395649/4573065
export type AllOf<T> = ['Needs to be all of', T];

/**
 * Creates a function that requires all keys of the generic type to be used as parameters.
 * The function itself will return the given parameters.
 */
export function allOf<T>(): <U extends T[]>(
  ...array: U & ([T] extends [U[number]] ? unknown : AllOf<T>[])
) => U & ([T] extends [U[number]] ? unknown : AllOf<T>[]) {
  return (...array) => array;
}