From 994a243f7f45ab0feb26532b7f5104ce146c7e1c Mon Sep 17 00:00:00 2001 From: Kartal Kaan Bozdogan Date: Sun, 13 Oct 2024 13:37:10 +0200 Subject: [PATCH] Fix more tests --- deno/lib/helpers/partialUtil.ts | 47 ++++++++++++++++----------------- deno/lib/types.ts | 20 +++++++------- src/helpers/partialUtil.ts | 47 ++++++++++++++++----------------- src/types.ts | 20 +++++++------- 4 files changed, 64 insertions(+), 70 deletions(-) diff --git a/deno/lib/helpers/partialUtil.ts b/deno/lib/helpers/partialUtil.ts index b9de239fd..be41eb74a 100644 --- a/deno/lib/helpers/partialUtil.ts +++ b/deno/lib/helpers/partialUtil.ts @@ -1,9 +1,9 @@ import type { + AnyZodObject, ZodArray, ZodNullable, ZodObject, ZodOptional, - ZodRawShape, ZodTuple, ZodTupleItems, ZodTypeAny, @@ -35,30 +35,29 @@ export namespace partialUtil { // ? "object" // T extends ZodOptional // ? 'optional' // : // : "rest"]; - export type DeepPartial = - T extends ZodObject - ? ZodObject< - { [k in keyof T["shape"]]: ZodOptional> }, - T["_def"]["unknownKeys"], - T["_def"]["catchall"] - > - : T extends ZodArray - ? ZodArray, Card> - : T extends ZodOptional - ? ZodOptional> - : T extends ZodNullable - ? ZodNullable> - : T extends ZodTuple - ? { - [k in keyof Items]: Items[k] extends ZodTypeAny - ? DeepPartial - : never; - } extends infer PI - ? PI extends ZodTupleItems - ? ZodTuple - : never + export type DeepPartial = T extends AnyZodObject + ? ZodObject< + { [k in keyof T["shape"]]: ZodOptional> }, + T["_def"]["unknownKeys"], + T["_def"]["catchall"] + > + : T extends ZodArray + ? ZodArray, Card> + : T extends ZodOptional + ? ZodOptional> + : T extends ZodNullable + ? ZodNullable> + : T extends ZodTuple + ? { + [k in keyof Items]: Items[k] extends ZodTypeAny + ? DeepPartial + : never; + } extends infer PI + ? PI extends ZodTupleItems + ? ZodTuple : never - : T; + : never + : T; // { // // optional: T extends ZodOptional ? T : ZodOptional; // // array: T extends ZodArray ? ZodArray> : never; diff --git a/deno/lib/types.ts b/deno/lib/types.ts index 59d82fdb4..17b80d604 100644 --- a/deno/lib/types.ts +++ b/deno/lib/types.ts @@ -2839,7 +2839,7 @@ export class ZodObject< }; } -export type AnyZodObject = ZodObject; +export type AnyZodObject = ZodObject; //////////////////////////////////////// //////////////////////////////////////// @@ -3347,17 +3347,15 @@ export interface ZodTupleDef< typeName: ZodFirstPartyTypeKind.ZodTuple; } -export type AnyZodTuple = ZodTuple< - [ZodTypeAny, ...ZodTypeAny[]] | [], - ZodTypeAny | null ->; +export type AnyZodTuple = ZodTuple<[] | ZodTupleItems, any, any | never>; export class ZodTuple< T extends [ZodTypeAny, ...ZodTypeAny[]] | [] = [ZodTypeAny, ...ZodTypeAny[]], - Rest extends ZodTypeAny | null = null + Rest extends ZodTypeAny | null = null, + Input = InputTypeOfTupleWithRest > extends ZodType< OutputTypeOfTupleWithRest, ZodTupleDef, - InputTypeOfTupleWithRest + Input > { _parse(input: ParseInput): ParseReturnType { const { status, ctx } = this._processInputParams(input); @@ -3788,7 +3786,7 @@ export class ZodSet extends ZodType< /////////////////////////////////////////// /////////////////////////////////////////// export interface ZodFunctionDef< - Args extends ZodTuple = ZodTuple, + Args extends AnyZodTuple = AnyZodTuple, Returns extends ZodTypeAny = ZodTypeAny > extends ZodTypeDef { args: Args; @@ -3797,21 +3795,21 @@ export interface ZodFunctionDef< } export type OuterTypeOfFunction< - Args extends ZodTuple, + Args extends AnyZodTuple, Returns extends ZodTypeAny > = input extends Array ? (...args: input) => Returns["_output"] : never; export type InnerTypeOfFunction< - Args extends ZodTuple, + Args extends AnyZodTuple, Returns extends ZodTypeAny > = Args["_output"] extends Array ? (...args: Args["_output"]) => input : never; export class ZodFunction< - Args extends ZodTuple, + Args extends AnyZodTuple, Returns extends ZodTypeAny > extends ZodType< OuterTypeOfFunction, diff --git a/src/helpers/partialUtil.ts b/src/helpers/partialUtil.ts index ebfa5ec31..23aa988ac 100644 --- a/src/helpers/partialUtil.ts +++ b/src/helpers/partialUtil.ts @@ -1,9 +1,9 @@ import type { + AnyZodObject, ZodArray, ZodNullable, ZodObject, ZodOptional, - ZodRawShape, ZodTuple, ZodTupleItems, ZodTypeAny, @@ -35,30 +35,29 @@ export namespace partialUtil { // ? "object" // T extends ZodOptional // ? 'optional' // : // : "rest"]; - export type DeepPartial = - T extends ZodObject - ? ZodObject< - { [k in keyof T["shape"]]: ZodOptional> }, - T["_def"]["unknownKeys"], - T["_def"]["catchall"] - > - : T extends ZodArray - ? ZodArray, Card> - : T extends ZodOptional - ? ZodOptional> - : T extends ZodNullable - ? ZodNullable> - : T extends ZodTuple - ? { - [k in keyof Items]: Items[k] extends ZodTypeAny - ? DeepPartial - : never; - } extends infer PI - ? PI extends ZodTupleItems - ? ZodTuple - : never + export type DeepPartial = T extends AnyZodObject + ? ZodObject< + { [k in keyof T["shape"]]: ZodOptional> }, + T["_def"]["unknownKeys"], + T["_def"]["catchall"] + > + : T extends ZodArray + ? ZodArray, Card> + : T extends ZodOptional + ? ZodOptional> + : T extends ZodNullable + ? ZodNullable> + : T extends ZodTuple + ? { + [k in keyof Items]: Items[k] extends ZodTypeAny + ? DeepPartial + : never; + } extends infer PI + ? PI extends ZodTupleItems + ? ZodTuple : never - : T; + : never + : T; // { // // optional: T extends ZodOptional ? T : ZodOptional; // // array: T extends ZodArray ? ZodArray> : never; diff --git a/src/types.ts b/src/types.ts index f9d96eeb9..84a0f0197 100644 --- a/src/types.ts +++ b/src/types.ts @@ -2839,7 +2839,7 @@ export class ZodObject< }; } -export type AnyZodObject = ZodObject; +export type AnyZodObject = ZodObject; //////////////////////////////////////// //////////////////////////////////////// @@ -3347,17 +3347,15 @@ export interface ZodTupleDef< typeName: ZodFirstPartyTypeKind.ZodTuple; } -export type AnyZodTuple = ZodTuple< - [ZodTypeAny, ...ZodTypeAny[]] | [], - ZodTypeAny | null ->; +export type AnyZodTuple = ZodTuple<[] | ZodTupleItems, any, any | never>; export class ZodTuple< T extends [ZodTypeAny, ...ZodTypeAny[]] | [] = [ZodTypeAny, ...ZodTypeAny[]], - Rest extends ZodTypeAny | null = null + Rest extends ZodTypeAny | null = null, + Input = InputTypeOfTupleWithRest > extends ZodType< OutputTypeOfTupleWithRest, ZodTupleDef, - InputTypeOfTupleWithRest + Input > { _parse(input: ParseInput): ParseReturnType { const { status, ctx } = this._processInputParams(input); @@ -3788,7 +3786,7 @@ export class ZodSet extends ZodType< /////////////////////////////////////////// /////////////////////////////////////////// export interface ZodFunctionDef< - Args extends ZodTuple = ZodTuple, + Args extends AnyZodTuple = AnyZodTuple, Returns extends ZodTypeAny = ZodTypeAny > extends ZodTypeDef { args: Args; @@ -3797,21 +3795,21 @@ export interface ZodFunctionDef< } export type OuterTypeOfFunction< - Args extends ZodTuple, + Args extends AnyZodTuple, Returns extends ZodTypeAny > = input extends Array ? (...args: input) => Returns["_output"] : never; export type InnerTypeOfFunction< - Args extends ZodTuple, + Args extends AnyZodTuple, Returns extends ZodTypeAny > = Args["_output"] extends Array ? (...args: Args["_output"]) => input : never; export class ZodFunction< - Args extends ZodTuple, + Args extends AnyZodTuple, Returns extends ZodTypeAny > extends ZodType< OuterTypeOfFunction,