#3060Easy

Unshift

Add elements to the beginning of tuples with TypeScript. Learn tuple manipulation and spread operators in this easy-level challenge on TypeScriptPro.

Prepend elements to arrays at the type level with Unshift! ⬅️

In this easy-level challenge, you'll implement the type version of Array.unshift in TypeScript. This type takes a tuple and an element, returning a new tuple with the element added at the beginning.

Like its JavaScript counterpart, this type operation demonstrates how to manipulate tuple positions at compile time. You'll solidify your understanding of spread operators and tuple type construction.

Challenge Instructions: Unshift

Easy

Implement the type version of Array.unshift

For example:

type Result = Unshift<[1, 2], 0> // [0, 1, 2]

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

Loading...

Video Walkthrough

Detailed Explanation

The Unshift type uses the spread operator to prepend an element to a tuple.

type Unshift<T extends unknown[], U> = [U, ...T]

How it works:

This mirrors JavaScript's unshift method perfectly, showing how TypeScript's type system can model array operations with the same intuitive syntax used at runtime.

This challenge is originally from here.

Share this challenge

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