-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
17 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,18 @@ | ||
type Bool = 'true' | 'false' | ||
type Key = string | number | symbol; | ||
import { ArraySchema } from "./ArraySchema"; | ||
import { MapSchema } from "./MapSchema"; | ||
|
||
type Not<X extends Bool> = { | ||
true: 'false', | ||
false: 'true' | ||
}[X] | ||
|
||
type HaveIntersection<S1 extends string, S2 extends string> = ( | ||
{ [K in S1]: 'true' } & | ||
{ [key: string]: 'false' } | ||
)[S2] | ||
|
||
type IsNeverWorker<S extends Key> = ( | ||
{ [K in S]: 'false' } & | ||
{ [key: string]: 'true' } | ||
)[S] | ||
|
||
// Worker needed because of https://github.com/Microsoft/TypeScript/issues/18118 | ||
type IsNever<T extends Key> = Not<HaveIntersection<IsNeverWorker<T>, 'false'>> | ||
|
||
type IsFunction<T> = IsNever<keyof T> | ||
|
||
export type NonFunctionProps<T> = { | ||
[K in keyof T]: { | ||
'false': K, | ||
'true': never | ||
}[IsFunction<T[K]>] | ||
}[keyof T]; | ||
export type NonFunctionProps<T> = Omit<T, { | ||
[K in keyof T]: T[K] extends Function ? K : never; | ||
}[keyof T]>; | ||
|
||
export type NonFunctionPropNames<T> = { | ||
[K in keyof T]: T[K] extends Function ? never : K | ||
}[keyof T]; | ||
|
||
export type ToJSON<T> = Partial<NonFunctionProps<{ | ||
[K in keyof T]: T[K] extends MapSchema<infer U> | ||
? Record<string, U> | ||
: T[K] extends ArraySchema<infer U> | ||
? U[] | ||
: T[K] | ||
}>>; |
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