Open 1wkk opened 1 year ago
/* _____________ Your Code Here _____________ */ type Permutation<T, P = T> = [T] extends [never] ? [] : P extends P ? [P, ...Permutation<Exclude<T, P>>] : never /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' type U = 'A' | 'B' | 'C' 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<boolean>, [false, true] | [true, false]>>, Expect<Equal<Permutation<never>, []>> ]
Exclude
Exclude<'a', 'a'>
never
T = never
T extends never
[T] extends [never]