#9142Medium

CheckRepeatedChars

Implement type CheckRepeatedChars<S> which will return whether type S contains duplicated chars. Learn union type manipulation in this medium-level challenge on TypeScriptPro.

In this medium-level challenge, you'll implement CheckRepeatedChars<S> which checks whether a string type contains any duplicated characters, returning true or false.

Challenge Instructions: CheckRepeatedChars

Medium

Implement type CheckRepeatedChars<S> which will return whether type S contains duplicated chars?

For example:

type CheckRepeatedChars<'abc'>   // false
type CheckRepeatedChars<'aba'>   // true

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

👋 Lifetime-License is leaving on August 10, 2026

Get it now for $29

One-time payment. Lifetime access to all pro challenges.

Loading...

Detailed Explanation

type CheckRepeatedChars<T extends string> =
  T extends `${infer First}${infer Rest}`
    ? Rest extends `${string}${First}${string}`
      ? true
      : CheckRepeatedChars<Rest>
    : false

How it works:

This challenge helps you understand template literal type pattern matching and recursive string analysis, and how to apply these concepts in real-world scenarios.

This challenge is originally from here.

Share this challenge

Learn the Concepts