Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code to enable type printing #1209

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
working on fixing tests
only-cliches committed Jan 12, 2024
commit 013c886d832db43ad3ebdd4230dbc26cf899483f
3 changes: 2 additions & 1 deletion src/struct.ts
Original file line number Diff line number Diff line change
@@ -33,13 +33,14 @@ export class Struct<T = unknown, S = unknown> {
type,
schema,
validator,
extend,
refiner,
coercer = (value: unknown) => value,
entries = function* () {},
} = props

this.type = type
this.extend = props.extend;
this.extend = extend
this.schema = schema
this.entries = entries
this.coercer = coercer
14 changes: 9 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -339,6 +339,7 @@ export type If<B extends Boolean, Then, Else> = B extends true ? Then : Else
*/

export type StructSchema<T> = [T] extends [string | undefined | null]

? [T] extends [IsMatch<T, string | undefined | null>]
? null
: [T] extends [IsUnion<T>]
@@ -354,18 +355,21 @@ export type StructSchema<T> = [T] extends [string | undefined | null]
? [T] extends [IsExactMatch<T, boolean>]
? null
: T
: T extends RegExp | Date | Function
? null
: T extends Set<infer A>
? Struct<A>
: T extends Record<infer A, infer B>
? [Struct<A>, Struct<B>]
: T extends Map<infer A, infer B>
? [A, B]
: T extends
| bigint
| symbol
| undefined
| null
| Function
| Date
| Error
| RegExp
| Map<any, any>
| WeakMap<any, any>
| Set<any>
| WeakSet<any>
| Promise<any>
? null