From 9cd5f331f61f95a541fc37b391bb3f5fb4f40fe4 Mon Sep 17 00:00:00 2001 From: Ifiok Jr Date: Thu, 5 Mar 2020 16:04:27 +0100 Subject: [PATCH] Update union-to-intersection.d.ts --- source/union-to-intersection.d.ts | 44 +++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/source/union-to-intersection.d.ts b/source/union-to-intersection.d.ts index 1e5aa688b..61d98412e 100644 --- a/source/union-to-intersection.d.ts +++ b/source/union-to-intersection.d.ts @@ -20,17 +20,17 @@ A more applicable example which could make its way into your library code follow import {UnionToIntersection} from 'type-fest'; class CommandOne { - commands: { - a1: () => undefined, - b1: () => undefined, - } + commands: { + a1: () => undefined, + b1: () => undefined, + } } class CommandTwo { - commands: { - a2: (argA: string) => undefined, - b2: (argB: string) => undefined, - } + commands: { + a2: (argA: string) => undefined, + b2: (argB: string) => undefined, + } } const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands); @@ -42,17 +42,17 @@ type Intersection = UnionToIntersection; ``` */ export type UnionToIntersection = ( - // `extends any` is always going to be the case and is used to convert the - // `Union` into a [distributive conditional - // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types). - Union extends any - // The union type is used as the only argument to a function since the union - // of function arguments is an intersection. - ? (distributedUnion: Union) => void - // This won't happen. - : never - // Infer the `Intersection` type since TypeScript represents the positional - // arguments of unions of functions as an intersection of the union. - ) extends ((mergedIntersection: infer Intersection) => void) - ? Intersection - : never; + // `extends any` is always going to be the case and is used to convert the + // `Union` into a [distributive conditional + // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types). + Union extends unknown + // The union type is used as the only argument to a function since the union + // of function arguments is an intersection. + ? (distributedUnion: Union) => void + // This won't happen. + : never + // Infer the `Intersection` type since TypeScript represents the positional + // arguments of unions of functions as an intersection of the union. + ) extends ((mergedIntersection: infer Intersection) => void) + ? Intersection + : never;