Last active
October 29, 2024 15:39
-
-
Save betafcc/f9084dd9f42ffea59ad6f2ff366b864f to your computer and use it in GitHub Desktop.
Revisions
-
betafcc revised this gist
Jul 25, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ /** * @example * type P = Permutation<1 | 2 | 3> * // [1, 2, 3] | [1, 3, 2] | [2, 1, 3] | [2, 3, 1] | [3, 1, 2] | [3, 2, 1] */ export type Permutation<U, T = U> = [U] extends [never] ? [] -
betafcc revised this gist
Jul 25, 2022 . 1 changed file with 5 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,11 @@ * type P = Permutation<1 | 2 | 3> * // [2, 3, 1] | [3, 2, 1] | [2, 1, 3] | [1, 2, 3] | [3, 1, 2] | [1, 3, 2] */ export type Permutation<U, T = U> = [U] extends [never] ? [] : T extends unknown ? [T, ...Permutation<Exclude<U, T>>] : never /** * @example @@ -19,14 +23,3 @@ export type UnionCount<U> = Permutation<U>['length'] */ export type KeyCount<T> = UnionCount<keyof T> -
betafcc revised this gist
Jul 24, 2022 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,10 +14,10 @@ export type UnionCount<U> = Permutation<U>['length'] /** * @example * type C = KeyCount<{ x: 1, y: 2 }> * // 2 */ export type KeyCount<T> = UnionCount<keyof T> type NestedPermutation<U> = Recurse<[U, ...(U extends never ? [] : [U])]> -
betafcc revised this gist
Jul 24, 2022 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,6 +12,13 @@ export type Permutation<U> = Flat<NestedPermutation<U>> */ export type UnionCount<U> = Permutation<U>['length'] /** * @example * type C = KeysCount<{ x: 1, y: 2 }> * // 2 */ export type KeysCount<T> = UnionCount<keyof T> type NestedPermutation<U> = Recurse<[U, ...(U extends never ? [] : [U])]> type Recurse<T extends unknown[]> = T extends [unknown, ...infer Rest] -
betafcc revised this gist
Jul 24, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ export type Permutation<U> = Flat<NestedPermutation<U>> /** * @example * type C = UnionCount<'a' | 'b' | 'c'> * // 3 */ export type UnionCount<U> = Permutation<U>['length'] -
betafcc revised this gist
Jul 24, 2022 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,16 @@ /** * @example * type P = Permutation<1 | 2 | 3> * // [2, 3, 1] | [3, 2, 1] | [2, 1, 3] | [1, 2, 3] | [3, 1, 2] | [1, 3, 2] */ export type Permutation<U> = Flat<NestedPermutation<U>> /** * @example * type C = Permutation<'a' | 'b' | 'c'> * // 3 */ export type UnionCount<U> = Permutation<U>['length'] type NestedPermutation<U> = Recurse<[U, ...(U extends never ? [] : [U])]> -
betafcc revised this gist
Jul 24, 2022 . 1 changed file with 2 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,16 +12,12 @@ export type UnionCount<U> = Permutation<U>['length'] */ export type Permutation<U> = Flat<NestedPermutation<U>> type NestedPermutation<U> = Recurse<[U, ...(U extends never ? [] : [U])]> type Recurse<T extends unknown[]> = T extends [unknown, ...infer Rest] ? [NestedPermutation<Exclude<T[0], Rest[number]>>, ...Rest] : [] type Flat<A> = A extends [[never, infer Head], infer Rest] ? [...Flat<Head>, Rest] : A extends [infer Head, infer Rest] -
betafcc created this gist
Jul 24, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ /** * @example * type C = Permutation<'a' | 'b' | 'c'> * // 3 */ export type UnionCount<U> = Permutation<U>['length'] /** * @example * type P = Permutation<1 | 2 | 3> * // [2, 3, 1] | [3, 2, 1] | [2, 1, 3] | [1, 2, 3] | [3, 1, 2] | [1, 3, 2] */ export type Permutation<U> = Flat<NestedPermutation<U>> /** * Expects input to be a pair of [Union, Single], will Exclude Single from Union * and Recurse to NestedPermutation */ type Recurse<T extends unknown[]> = T extends [unknown, ...infer Rest] ? [NestedPermutation<Exclude<T[0], Rest[number]>>, ...Rest] : [] type NestedPermutation<U> = Recurse<[U, ...(U extends never ? [] : [U])]> type Flat<A> = A extends [[never, infer Head], infer Rest] ? [...Flat<Head>, Rest] : A extends [infer Head, infer Rest] ? [...Flat<Head>, Rest] : [A]