1. Combine multiple modifier keys, but the same modifier key combination cannot appear. Master advanced TypeScript type manipulation in this medium-level challenge on TypeScriptPro.
In this medium-level challenge, you'll implement Combs<T> which generates all unique two-key combinations from a tuple of modifier keys, preserving the original order so that 'cmd ctrl' is valid but 'ctrl cmd' is not.
ModifierKeys provided, the priority of the previous value is higher than the latter value; that is, cmd ctrl is OK, but ctrl cmd is not allowed.Change the following code to make the test cases pass (no type check errors).
type Combs<T extends any[]> = T extends [infer First extends string, ...infer Rest extends string[]]
? `${First} ${Rest[number]}` | Combs<Rest>
: neverHow it works:
T extends [infer First extends string, ...infer Rest extends string[]] destructures the tuple, pulling out the first element and the remaining elements${First} ${Rest[number]} creates a union of template literal strings by pairing First with every element in Rest using Rest[number]Combs<Rest> recursively processes the remaining elements, so each subsequent element is paired only with elements that come after itnever when the tuple is empty or has one element, ending the recursionThis challenge helps you understand recursive type processing of tuples combined with template literal types and how to apply these concepts in real-world scenarios.
This challenge is originally from here.
Be the first to access the course, unlock exclusive launch bonuses, and get special early-bird pricing before anyone else.
Only 27 Spots left
Get 1 month early access
Pre-Launch discount