type-challenges icon indicating copy to clipboard operation
type-challenges copied to clipboard

296 - Permutation

Open Tandayuan opened this issue 2 years ago • 0 comments

// 你的答案
type IsNever<T> = [T] extends [never] ? ([never] extends [T] ? true : false) : false

type Permutation<T extends boolean | string> = 
{ [P in `${T}`]: [P extends `${infer Bool extends boolean}` ? Bool : P, ...Permutation<Exclude<`${T}`, P>> ] } [`${T}`] extends infer R extends any[] ? 
IsNever<T> extends true ? [] : R
:never;

Tandayuan avatar Nov 13 '22 16:11 Tandayuan