#18142Medium

All

Returns true if all elements of the list are equal to the second parameter passed in, false if there are any mismatches. Learn array type operations in this medium-level challenge on TypeScriptPro.

In this medium-level challenge, you'll implement All<T, V> which returns true if all elements of the tuple T are exactly equal to the type V, and false otherwise.

Challenge Instructions: All

Medium

Returns true if all elements of the list are equal to the second parameter passed in, false if there are any mismatches.

For example

type Test1 = [1, 1, 1]
type Test2 = [1, 1, 2]
 
type Todo = All<Test1, 1> // should be same as true
type Todo2 = All<Test2, 1> // should be same as false

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

Loading...

Detailed Explanation

type All<T extends unknown[], V> = T extends [infer First, ...infer Rest]
  ? Equal<First, V> extends true
    ? All<Rest, V>
    : false
  : true

How it works:

This challenge helps you understand recursive tuple traversal and strict type equality checking, and how to apply these concepts in real-world scenarios.

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