Skip to content

Commit

Permalink
feat: add UnionToIntersection
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshRosenstein committed Apr 15, 2019
1 parent d0378b5 commit a9a4b4d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/types/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ export type Nominal<T, N extends string> = T & Tagged<N>;
* @returns a the type union with a promise containing the given type
*/
export type PromiseOr<T> = Promise<T> | T;


/**
* Defines an intersection type of all union items.
* @param U Union of any types that will be intersected.
* @returns U items intersected
* @see https://stackoverflow.com/a/50375286/9259330
*/
export type UnionToIntersection<U> =
(U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;

0 comments on commit a9a4b4d

Please sign in to comment.