#296Medium

Permutation

Implement permutation type that transforms union types into the array that includes permutations of unions. Learn union type manipulation in this medium-level challenge on TypeScriptPro.

In this medium-level challenge, you'll implement a Permutation type that transforms a union type into a union of all possible tuple orderings of its members.

Challenge Instructions: Permutation

Medium

Implement permutation type that transforms union types into the array that includes permutations of unions.

type perm = Permutation<'A' | 'B' | 'C'>; // ['A', 'B', 'C'] | ['A', 'C', 'B'] | ['B', 'A', 'C'] | ['B', 'C', 'A'] | ['C', 'A', 'B'] | ['C', 'B', 'A']

Change the following code to make the test cases pass (no type check errors).

Loading...

Detailed Explanation

type Permutation<T, U = T> =
  [T] extends [never]
    ? []
    : U extends U
      ? [U, ...Permutation<Exclude<T, U>>]
      : never

How it works:

This challenge helps you understand distributive conditional types and recursive union manipulation, and how to apply these concepts in real-world scenarios.

This challenge is originally from here.

Share this challenge

Learn the Concepts

Join early, learn faster.

Be the first to access the course, unlock exclusive launch bonuses, and get special early-bird pricing before anyone else.

No spam, unsubscribe at any time. We respect your privacy.

Limited Availability

Only 27 Spots left

Early Access

Get 1 month early access

>75% Off

Pre-Launch discount