Permutation
提出詳細
type Impl<T,U> = T extends unknown ? (Exclude<U,T> extends never ? [T] : [T,...Wrapper<Exclude<U,T>>]) : never type Wrapper<T> = { [key in T & PropertyKey]: Impl<key,T> }[T & PropertyKey] type Permutation<T> = [T] extends [never] ? [] : Wrapper<T>
提出日時 | 2023-09-13 16:27:51 |
---|---|
問題 | Permutation |
ユーザー | sankantsu |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<Permutation<'A'>, ['A']>>, Expect<Equal<Permutation<'A' | 'B' | 'C'>, ['A', 'B', 'C'] | ['A', 'C', 'B'] | ['B', 'A', 'C'] | ['B', 'C', 'A'] | ['C', 'A', 'B'] | ['C', 'B', 'A']>>, Expect<Equal<Permutation<'B' | 'A' | 'C'>, ['A', 'B', 'C'] | ['A', 'C', 'B'] | ['B', 'A', 'C'] | ['B', 'C', 'A'] | ['C', 'A', 'B'] | ['C', 'B', 'A']>>, Expect<Equal<Permutation<never>, []>>, ]