Skip to content

Commit

Permalink
Reformat with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
arturmuller committed Mar 11, 2024
1 parent 6e6e2af commit 56c5d34
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 57 deletions.
6 changes: 3 additions & 3 deletions src/structs/refinements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { toFailures } from '../utils'

export function empty<
T extends string | any[] | Map<any, any> | Set<any>,
S extends any
S extends any,
>(struct: Struct<T, S>): Struct<T, S> {
return refine(struct, 'empty', (value) => {
const size = getSize(value)
Expand Down Expand Up @@ -76,7 +76,7 @@ export function min<T extends number | Date, S extends any>(

export function nonempty<
T extends string | any[] | Map<any, any> | Set<any>,
S extends any
S extends any,
>(struct: Struct<T, S>): Struct<T, S> {
return refine(struct, 'nonempty', (value) => {
const size = getSize(value)
Expand Down Expand Up @@ -108,7 +108,7 @@ export function pattern<T extends string, S extends any>(

export function size<
T extends string | number | Date | any[] | Map<any, any> | Set<any>,
S extends any
S extends any,
>(struct: Struct<T, S>, min: number, max: number = min): Struct<T, S> {
const expected = `Expected a ${struct.type}`
const of = min === max ? `of \`${min}\`` : `between \`${min}\` and \`${max}\``
Expand Down
6 changes: 3 additions & 3 deletions src/structs/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function assign<A extends ObjectSchema, B extends ObjectSchema>(
export function assign<
A extends ObjectSchema,
B extends ObjectSchema,
C extends ObjectSchema
C extends ObjectSchema,
>(
A: Struct<ObjectType<A>, A>,
B: Struct<ObjectType<B>, B>,
Expand All @@ -26,7 +26,7 @@ export function assign<
A extends ObjectSchema,
B extends ObjectSchema,
C extends ObjectSchema,
D extends ObjectSchema
D extends ObjectSchema,
>(
A: Struct<ObjectType<A>, A>,
B: Struct<ObjectType<B>, B>,
Expand All @@ -41,7 +41,7 @@ export function assign<
B extends ObjectSchema,
C extends ObjectSchema,
D extends ObjectSchema,
E extends ObjectSchema
E extends ObjectSchema,
>(
A: Struct<ObjectType<A>, A>,
B: Struct<ObjectType<B>, B>,
Expand Down
99 changes: 49 additions & 50 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,10 @@ export type IsMatch<T, G> = T extends G ? (G extends T ? T : never) : never
* Check if a type is an exact match.
*/

export type IsExactMatch<T, U> = (<G>() => G extends T ? 1 : 2) extends <
G
>() => G extends U ? 1 : 2
? T
: never
export type IsExactMatch<T, U> =
(<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2
? T
: never

/**
* Check if a type is a record type.
Expand All @@ -258,14 +257,14 @@ export type IsRecord<T> = T extends object
export type IsTuple<T> = T extends [any]
? T
: T extends [any, any]
? T
: T extends [any, any, any]
? T
: T extends [any, any, any, any]
? T
: T extends [any, any, any, any, any]
? T
: never
? T
: T extends [any, any, any]
? T
: T extends [any, any, any, any]
? T
: T extends [any, any, any, any, any]
? T
: never

/**
* Check if a type is a union.
Expand Down Expand Up @@ -342,42 +341,42 @@ export type StructSchema<T> = [T] extends [string | undefined | null]
? [T] extends [IsMatch<T, string | undefined | null>]
? null
: [T] extends [IsUnion<T>]
? EnumSchema<T>
: T
? EnumSchema<T>
: T
: [T] extends [number | undefined | null]
? [T] extends [IsMatch<T, number | undefined | null>]
? null
: [T] extends [IsUnion<T>]
? EnumSchema<T>
: T
: [T] extends [boolean]
? [T] extends [IsExactMatch<T, boolean>]
? null
: T
: T extends
| bigint
| symbol
| undefined
| null
| Function
| Date
| Error
| RegExp
| Map<any, any>
| WeakMap<any, any>
| Set<any>
| WeakSet<any>
| Promise<any>
? null
: T extends Array<infer E>
? T extends IsTuple<T>
? null
: Struct<E>
: T extends object
? T extends IsRecord<T>
? null
: { [K in keyof T]: Describe<T[K]> }
: null
? [T] extends [IsMatch<T, number | undefined | null>]
? null
: [T] extends [IsUnion<T>]
? EnumSchema<T>
: T
: [T] extends [boolean]
? [T] extends [IsExactMatch<T, boolean>]
? null
: T
: T extends
| bigint
| symbol
| undefined
| null
| Function
| Date
| Error
| RegExp
| Map<any, any>
| WeakMap<any, any>
| Set<any>
| WeakSet<any>
| Promise<any>
? null
: T extends Array<infer E>
? T extends IsTuple<T>
? null
: Struct<E>
: T extends object
? T extends IsRecord<T>
? null
: { [K in keyof T]: Describe<T[K]> }
: null

/**
* A schema for tuple structs.
Expand All @@ -400,7 +399,7 @@ export type AnyStruct = Struct<any, any>

export type InferStructTuple<
Tuple extends AnyStruct[],
Length extends number = Tuple['length']
Length extends number = Tuple['length'],
> = Length extends Length
? number extends Length
? Tuple
Expand All @@ -410,7 +409,7 @@ type _InferTuple<
Tuple extends AnyStruct[],
Length extends number,
Accumulated extends unknown[],
Index extends number = Accumulated['length']
Index extends number = Accumulated['length'],
> = Index extends Length
? Accumulated
: _InferTuple<Tuple, Length, [...Accumulated, Infer<Tuple[Index]>]>
2 changes: 1 addition & 1 deletion test/typings/tuple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test<
'38',
'39',
'40',
'41'
'41',
]
>((x) => {
assert(
Expand Down

0 comments on commit 56c5d34

Please sign in to comment.