type-challenges / type-challenges

Collection of TypeScript type challenges with online judge

Home Page:https://tsch.js.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

5360 - Unique

nuonuonuonuoyan opened this issue · comments

type UniqueRest<T extends any[], K extends any> = T extends [
  infer F,
  ...infer R
]
  ? Equal<F, K> extends true
    ? [...UniqueRest<R, K>]
    : [F, ...UniqueRest<R, K>]
  : [];

type Unique<T extends any[]> = T extends [infer F, ...infer R]
  ? [F, ...Unique<UniqueRest<R, F>>]
  : [];