Implement type `CheckRepeatedChars<T>` which will return whether type `T` contains duplicated member Master advanced TypeScript type manipulation in this medium-level challenge on TypeScriptPro.
In this medium-level challenge, you'll implement CheckRepeatedTuple<T> which checks whether a tuple type contains any duplicated members, returning true or false.
Implement type CheckRepeatedChars<T> which will return whether type T contains duplicated member
For example:
type CheckRepeatedTuple<[1, 2, 3]> // false
type CheckRepeatedTuple<[1, 2, 1]> // trueChange the following code to make the test cases pass (no type check errors).
type Includes<T extends unknown[], V> = T extends [infer First, ...infer Rest]
? Equal<First, V> extends true
? true
: Includes<Rest, V>
: false
type CheckRepeatedTuple<T extends unknown[]> = T extends [infer First, ...infer Rest]
? Includes<Rest, First> extends true
? true
: CheckRepeatedTuple<Rest>
: falseHow it works:
Includes<T, V> is a helper type that checks if a value V exists anywhere in the tuple T using strict Equal comparisons to handle edge cases like any, never, and unknownCheckRepeatedTuple<T> processes the tuple by extracting the first element with infer First and the rest with ...infer RestIncludes<Rest, First>trueCheckRepeatedTuple<Rest> to check subsequent elementsfalse, meaning no duplicates were foundEqual instead of extends ensures correct handling of special types -- for example, any and unknown are treated as distinct typesThis challenge helps you understand recursive tuple analysis with strict type equality, 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