Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(enum): return enum from object keys (#1216)
* feat(enum): return enum from object keys * docs(enum): add enum documentation * docs: fix documentation * Change enum to keyof * Fix lint * Run prettier * Fix Deno tests Co-authored-by: Colin McDonnell <colinmcd@alum.mit.edu>
- Loading branch information
Showing
10 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export namespace enumUtil { | ||
type UnionToIntersectionFn<T> = ( | ||
T extends unknown ? (k: () => T) => void : never | ||
) extends (k: infer Intersection) => void | ||
? Intersection | ||
: never; | ||
|
||
type GetUnionLast<T> = UnionToIntersectionFn<T> extends () => infer Last | ||
? Last | ||
: never; | ||
|
||
type UnionToTuple<T, Tuple extends unknown[] = []> = [T] extends [never] | ||
? Tuple | ||
: UnionToTuple<Exclude<T, GetUnionLast<T>>, [GetUnionLast<T>, ...Tuple]>; | ||
|
||
type CastToStringTuple<T> = T extends [string, ...string[]] ? T : never; | ||
|
||
export type UnionToTupleString<T> = CastToStringTuple<UnionToTuple<T>>; | ||
} |
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// @ts-ignore TS6133 | ||
import { test } from "@jest/globals"; | ||
|
||
import { z } from ".."; | ||
|
||
interface Category { | ||
|
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export namespace enumUtil { | ||
type UnionToIntersectionFn<T> = ( | ||
T extends unknown ? (k: () => T) => void : never | ||
) extends (k: infer Intersection) => void | ||
? Intersection | ||
: never; | ||
|
||
type GetUnionLast<T> = UnionToIntersectionFn<T> extends () => infer Last | ||
? Last | ||
: never; | ||
|
||
type UnionToTuple<T, Tuple extends unknown[] = []> = [T] extends [never] | ||
? Tuple | ||
: UnionToTuple<Exclude<T, GetUnionLast<T>>, [GetUnionLast<T>, ...Tuple]>; | ||
|
||
type CastToStringTuple<T> = T extends [string, ...string[]] ? T : never; | ||
|
||
export type UnionToTupleString<T> = CastToStringTuple<UnionToTuple<T>>; | ||
} |
This file contains 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 characters