[Typescript Challenges] 146 Medium - CheckRepeatedTuple
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]> // true
/* _____________ Your Code Here _____________ */
export type Includes<T extends readonly any[], U> = T extends [
infer F,
...infer RT
]
? Equal<F, U> extends true
? true
: Includes<RT, U>
: false;
type CheckRepeatedTuple<T extends unknown[]> = T extends [infer Check, ...infer REST] ? Includes<REST, Check> : false;
/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
import { ExpectFalse, NotEqual } from '@type-challenges/utils'
type cases = [
Expect<Equal<CheckRepeatedTuple<[number, number, string, boolean]>, true>>,
Expect<Equal<CheckRepeatedTuple<[number, string]>, false>>,
Expect<Equal<CheckRepeatedTuple<[1, 2, 3]>, false>>,
Expect<Equal<CheckRepeatedTuple<[1, 2, 1]>, true>>,
Expect<Equal<CheckRepeatedTuple<[]>, false>>,
Expect<Equal<CheckRepeatedTuple<string[]>, false>>,
]