rimo030 / type-challenges

Collection of TypeScript type challenges with online judge
https://tsch.js.org/
MIT License
3 stars 0 forks source link

no - 8767 Combination #110

Open rimo030 opened 5 months ago

rimo030 commented 5 months ago
type Combination<T extends string[], U = T[number], K = U> = K extends string
  ? `${K}` | `${K} ${Combination<[], Exclude<U, K>>}`
  : never
type cases = [
  Expect<Equal<Combination<['foo', 'bar', 'baz']>, 'foo' | 'bar' | 'baz' | 'foo bar' | 'foo bar baz' | 'foo baz' | 'foo baz bar' | 'bar foo' | 'bar foo baz' | 'bar baz' | 'bar baz foo' | 'baz foo' | 'baz foo bar' | 'baz bar' | 'baz bar foo'>>,
]