Skip to content

Commit

Permalink
Don't worry about empty tuple types in TupleToIntersection. (#4502)
Browse files Browse the repository at this point in the history
Although a zero-argument call to `mergeDeep` was always pretty pointless,
it seemed worth handling that case for the sake of completeness.

Well, apparently empty tuple types are forbidden by section 3.8.5 of the
TypeScript spec, so (some versions of) the compiler complain about the
`[]` in the `T extends []` case of `TupleToIntersection`:
https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#385-tuple-type-literals

Since we never really needed this case in the first place, the easy
solution is to remove it.

Note that the final cases in `TupleToIntersection` continue to cover the
zero-argument case, for whatever it may be worth:

  T extends (infer U)[] ? U : any

Should fix #4501.
  • Loading branch information
benjamn committed Feb 26, 2019
1 parent a440242 commit bcaa0b7
Showing 1 changed file with 0 additions and 1 deletion.
1 change: 0 additions & 1 deletion packages/apollo-utilities/src/util/mergeDeep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const { hasOwnProperty } = Object.prototype;
// true & false, and the inferred type ends up as unknown in many cases),
// in addition to being nearly impossible to explain/understand.
export type TupleToIntersection<T extends any[]> =
T extends [] ? {} :
T extends [infer A] ? A :
T extends [infer A, infer B] ? A & B :
T extends [infer A, infer B, infer C] ? A & B & C :
Expand Down

0 comments on commit bcaa0b7

Please sign in to comment.