Skip to content

Commit

Permalink
Fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mstniy committed Oct 13, 2024
1 parent 304c024 commit 994a243
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 70 deletions.
47 changes: 23 additions & 24 deletions deno/lib/helpers/partialUtil.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type {
AnyZodObject,
ZodArray,
ZodNullable,
ZodObject,
ZodOptional,
ZodRawShape,
ZodTuple,
ZodTupleItems,
ZodTypeAny,
Expand Down Expand Up @@ -35,30 +35,29 @@ export namespace partialUtil {
// ? "object" // T extends ZodOptional<any> // ? 'optional' // :
// : "rest"];

export type DeepPartial<T extends ZodTypeAny> =
T extends ZodObject<ZodRawShape>
? ZodObject<
{ [k in keyof T["shape"]]: ZodOptional<DeepPartial<T["shape"][k]>> },
T["_def"]["unknownKeys"],
T["_def"]["catchall"]
>
: T extends ZodArray<infer Type, infer Card>
? ZodArray<DeepPartial<Type>, Card>
: T extends ZodOptional<infer Type>
? ZodOptional<DeepPartial<Type>>
: T extends ZodNullable<infer Type>
? ZodNullable<DeepPartial<Type>>
: T extends ZodTuple<infer Items>
? {
[k in keyof Items]: Items[k] extends ZodTypeAny
? DeepPartial<Items[k]>
: never;
} extends infer PI
? PI extends ZodTupleItems
? ZodTuple<PI>
: never
export type DeepPartial<T extends ZodTypeAny> = T extends AnyZodObject
? ZodObject<
{ [k in keyof T["shape"]]: ZodOptional<DeepPartial<T["shape"][k]>> },
T["_def"]["unknownKeys"],
T["_def"]["catchall"]
>
: T extends ZodArray<infer Type, infer Card>
? ZodArray<DeepPartial<Type>, Card>
: T extends ZodOptional<infer Type>
? ZodOptional<DeepPartial<Type>>
: T extends ZodNullable<infer Type>
? ZodNullable<DeepPartial<Type>>
: T extends ZodTuple<infer Items>
? {
[k in keyof Items]: Items[k] extends ZodTypeAny
? DeepPartial<Items[k]>
: never;
} extends infer PI
? PI extends ZodTupleItems
? ZodTuple<PI>
: never
: T;
: never
: T;
// {
// // optional: T extends ZodOptional<ZodTypeAny> ? T : ZodOptional<T>;
// // array: T extends ZodArray<infer Type> ? ZodArray<DeepPartial<Type>> : never;
Expand Down
20 changes: 9 additions & 11 deletions deno/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2839,7 +2839,7 @@ export class ZodObject<
};
}

export type AnyZodObject = ZodObject<any, any, any>;
export type AnyZodObject = ZodObject<any, any, any, any, never>;

////////////////////////////////////////
////////////////////////////////////////
Expand Down Expand Up @@ -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<T, Rest>
> extends ZodType<
OutputTypeOfTupleWithRest<T, Rest>,
ZodTupleDef<T, Rest>,
InputTypeOfTupleWithRest<T, Rest>
Input
> {
_parse(input: ParseInput): ParseReturnType<this["_output"]> {
const { status, ctx } = this._processInputParams(input);
Expand Down Expand Up @@ -3788,7 +3786,7 @@ export class ZodSet<Value extends ZodTypeAny = ZodTypeAny> extends ZodType<
///////////////////////////////////////////
///////////////////////////////////////////
export interface ZodFunctionDef<
Args extends ZodTuple<any, any> = ZodTuple<any, any>,
Args extends AnyZodTuple = AnyZodTuple,
Returns extends ZodTypeAny = ZodTypeAny
> extends ZodTypeDef {
args: Args;
Expand All @@ -3797,21 +3795,21 @@ export interface ZodFunctionDef<
}

export type OuterTypeOfFunction<
Args extends ZodTuple<any, any>,
Args extends AnyZodTuple,
Returns extends ZodTypeAny
> = input<Args> extends Array<any>
? (...args: input<Args>) => Returns["_output"]
: never;

export type InnerTypeOfFunction<
Args extends ZodTuple<any, any>,
Args extends AnyZodTuple,
Returns extends ZodTypeAny
> = Args["_output"] extends Array<any>
? (...args: Args["_output"]) => input<Returns>
: never;

export class ZodFunction<
Args extends ZodTuple<any, any>,
Args extends AnyZodTuple,
Returns extends ZodTypeAny
> extends ZodType<
OuterTypeOfFunction<Args, Returns>,
Expand Down
47 changes: 23 additions & 24 deletions src/helpers/partialUtil.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type {
AnyZodObject,
ZodArray,
ZodNullable,
ZodObject,
ZodOptional,
ZodRawShape,
ZodTuple,
ZodTupleItems,
ZodTypeAny,
Expand Down Expand Up @@ -35,30 +35,29 @@ export namespace partialUtil {
// ? "object" // T extends ZodOptional<any> // ? 'optional' // :
// : "rest"];

export type DeepPartial<T extends ZodTypeAny> =
T extends ZodObject<ZodRawShape>
? ZodObject<
{ [k in keyof T["shape"]]: ZodOptional<DeepPartial<T["shape"][k]>> },
T["_def"]["unknownKeys"],
T["_def"]["catchall"]
>
: T extends ZodArray<infer Type, infer Card>
? ZodArray<DeepPartial<Type>, Card>
: T extends ZodOptional<infer Type>
? ZodOptional<DeepPartial<Type>>
: T extends ZodNullable<infer Type>
? ZodNullable<DeepPartial<Type>>
: T extends ZodTuple<infer Items>
? {
[k in keyof Items]: Items[k] extends ZodTypeAny
? DeepPartial<Items[k]>
: never;
} extends infer PI
? PI extends ZodTupleItems
? ZodTuple<PI>
: never
export type DeepPartial<T extends ZodTypeAny> = T extends AnyZodObject
? ZodObject<
{ [k in keyof T["shape"]]: ZodOptional<DeepPartial<T["shape"][k]>> },
T["_def"]["unknownKeys"],
T["_def"]["catchall"]
>
: T extends ZodArray<infer Type, infer Card>
? ZodArray<DeepPartial<Type>, Card>
: T extends ZodOptional<infer Type>
? ZodOptional<DeepPartial<Type>>
: T extends ZodNullable<infer Type>
? ZodNullable<DeepPartial<Type>>
: T extends ZodTuple<infer Items>
? {
[k in keyof Items]: Items[k] extends ZodTypeAny
? DeepPartial<Items[k]>
: never;
} extends infer PI
? PI extends ZodTupleItems
? ZodTuple<PI>
: never
: T;
: never
: T;
// {
// // optional: T extends ZodOptional<ZodTypeAny> ? T : ZodOptional<T>;
// // array: T extends ZodArray<infer Type> ? ZodArray<DeepPartial<Type>> : never;
Expand Down
20 changes: 9 additions & 11 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2839,7 +2839,7 @@ export class ZodObject<
};
}

export type AnyZodObject = ZodObject<any, any, any>;
export type AnyZodObject = ZodObject<any, any, any, any, never>;

////////////////////////////////////////
////////////////////////////////////////
Expand Down Expand Up @@ -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<T, Rest>
> extends ZodType<
OutputTypeOfTupleWithRest<T, Rest>,
ZodTupleDef<T, Rest>,
InputTypeOfTupleWithRest<T, Rest>
Input
> {
_parse(input: ParseInput): ParseReturnType<this["_output"]> {
const { status, ctx } = this._processInputParams(input);
Expand Down Expand Up @@ -3788,7 +3786,7 @@ export class ZodSet<Value extends ZodTypeAny = ZodTypeAny> extends ZodType<
///////////////////////////////////////////
///////////////////////////////////////////
export interface ZodFunctionDef<
Args extends ZodTuple<any, any> = ZodTuple<any, any>,
Args extends AnyZodTuple = AnyZodTuple,
Returns extends ZodTypeAny = ZodTypeAny
> extends ZodTypeDef {
args: Args;
Expand All @@ -3797,21 +3795,21 @@ export interface ZodFunctionDef<
}

export type OuterTypeOfFunction<
Args extends ZodTuple<any, any>,
Args extends AnyZodTuple,
Returns extends ZodTypeAny
> = input<Args> extends Array<any>
? (...args: input<Args>) => Returns["_output"]
: never;

export type InnerTypeOfFunction<
Args extends ZodTuple<any, any>,
Args extends AnyZodTuple,
Returns extends ZodTypeAny
> = Args["_output"] extends Array<any>
? (...args: Args["_output"]) => input<Returns>
: never;

export class ZodFunction<
Args extends ZodTuple<any, any>,
Args extends AnyZodTuple,
Returns extends ZodTypeAny
> extends ZodType<
OuterTypeOfFunction<Args, Returns>,
Expand Down

0 comments on commit 994a243

Please sign in to comment.