From 56c5d34392b534d01c7d3db7760b711e7a680aee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20M=C3=BCller?= Date: Mon, 11 Mar 2024 15:45:44 +0100 Subject: [PATCH] Reformat with prettier --- src/structs/refinements.ts | 6 +-- src/structs/utilities.ts | 6 +-- src/utils.ts | 99 +++++++++++++++++++------------------- test/typings/tuple.ts | 2 +- 4 files changed, 56 insertions(+), 57 deletions(-) diff --git a/src/structs/refinements.ts b/src/structs/refinements.ts index e3f7736d..a99621ee 100644 --- a/src/structs/refinements.ts +++ b/src/structs/refinements.ts @@ -7,7 +7,7 @@ import { toFailures } from '../utils' export function empty< T extends string | any[] | Map | Set, - S extends any + S extends any, >(struct: Struct): Struct { return refine(struct, 'empty', (value) => { const size = getSize(value) @@ -76,7 +76,7 @@ export function min( export function nonempty< T extends string | any[] | Map | Set, - S extends any + S extends any, >(struct: Struct): Struct { return refine(struct, 'nonempty', (value) => { const size = getSize(value) @@ -108,7 +108,7 @@ export function pattern( export function size< T extends string | number | Date | any[] | Map | Set, - S extends any + S extends any, >(struct: Struct, min: number, max: number = min): Struct { const expected = `Expected a ${struct.type}` const of = min === max ? `of \`${min}\`` : `between \`${min}\` and \`${max}\`` diff --git a/src/structs/utilities.ts b/src/structs/utilities.ts index d2162a3d..7b27da49 100644 --- a/src/structs/utilities.ts +++ b/src/structs/utilities.ts @@ -16,7 +16,7 @@ export function assign( export function assign< A extends ObjectSchema, B extends ObjectSchema, - C extends ObjectSchema + C extends ObjectSchema, >( A: Struct, A>, B: Struct, B>, @@ -26,7 +26,7 @@ export function assign< A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema, - D extends ObjectSchema + D extends ObjectSchema, >( A: Struct, A>, B: Struct, B>, @@ -41,7 +41,7 @@ export function assign< B extends ObjectSchema, C extends ObjectSchema, D extends ObjectSchema, - E extends ObjectSchema + E extends ObjectSchema, >( A: Struct, A>, B: Struct, B>, diff --git a/src/utils.ts b/src/utils.ts index 92df9755..c6a022e0 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -236,11 +236,10 @@ export type IsMatch = T extends G ? (G extends T ? T : never) : never * Check if a type is an exact match. */ -export type IsExactMatch = (() => G extends T ? 1 : 2) extends < - G ->() => G extends U ? 1 : 2 - ? T - : never +export type IsExactMatch = + (() => G extends T ? 1 : 2) extends () => G extends U ? 1 : 2 + ? T + : never /** * Check if a type is a record type. @@ -258,14 +257,14 @@ export type IsRecord = T extends object export type IsTuple = 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. @@ -342,42 +341,42 @@ export type StructSchema = [T] extends [string | undefined | null] ? [T] extends [IsMatch] ? null : [T] extends [IsUnion] - ? EnumSchema - : T + ? EnumSchema + : T : [T] extends [number | undefined | null] - ? [T] extends [IsMatch] - ? null - : [T] extends [IsUnion] - ? EnumSchema - : T - : [T] extends [boolean] - ? [T] extends [IsExactMatch] - ? null - : T - : T extends - | bigint - | symbol - | undefined - | null - | Function - | Date - | Error - | RegExp - | Map - | WeakMap - | Set - | WeakSet - | Promise - ? null - : T extends Array - ? T extends IsTuple - ? null - : Struct - : T extends object - ? T extends IsRecord - ? null - : { [K in keyof T]: Describe } - : null + ? [T] extends [IsMatch] + ? null + : [T] extends [IsUnion] + ? EnumSchema + : T + : [T] extends [boolean] + ? [T] extends [IsExactMatch] + ? null + : T + : T extends + | bigint + | symbol + | undefined + | null + | Function + | Date + | Error + | RegExp + | Map + | WeakMap + | Set + | WeakSet + | Promise + ? null + : T extends Array + ? T extends IsTuple + ? null + : Struct + : T extends object + ? T extends IsRecord + ? null + : { [K in keyof T]: Describe } + : null /** * A schema for tuple structs. @@ -400,7 +399,7 @@ export type AnyStruct = Struct export type InferStructTuple< Tuple extends AnyStruct[], - Length extends number = Tuple['length'] + Length extends number = Tuple['length'], > = Length extends Length ? number extends Length ? Tuple @@ -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]> diff --git a/test/typings/tuple.ts b/test/typings/tuple.ts index 4889083b..816a8540 100644 --- a/test/typings/tuple.ts +++ b/test/typings/tuple.ts @@ -49,7 +49,7 @@ test< '38', '39', '40', - '41' + '41', ] >((x) => { assert(