Skip to content
Discussion options

You must be logged in to vote

This works too but it is a bit more complicated. Feel free to try it out in our playground.

import * as v from 'valibot';

/**
 * Converts union to intersection type.
 */
type UnionToIntersect<TUnion> =
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  (TUnion extends any ? (arg: TUnion) => void : never) extends (
    arg: infer Intersect
  ) => void
    ? Intersect
    : never;

/**
 * Converts union to tuple type using an accumulator.
 *
 * For more information: {@link https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html#tail-recursion-elimination-on-conditional-types}
 */
type UnionToTupleHelper<TUnion, TResult extends unknown[]> =
  UnionToIn…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@fabian-hiller
Comment options

Answer selected by Perdolique
@Perdolique
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants