Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2954f40

Browse files
authored
Fix json (#4630)
* Fix json* Tweaks* Clean up* Clean up
1 parentc58bd9b commit2954f40

File tree

4 files changed

+49
-99
lines changed

4 files changed

+49
-99
lines changed

‎packages/zod/src/v4/classic/schemas.ts‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ export function date(params?: string | core.$ZodDateParams): ZodDate {
987987

988988
// ZodArray
989989
exportinterfaceZodArray<Textendscore.SomeType=core.$ZodType>
990-
extendsZodType<any,any,core.$ZodArrayInternals<T>>,
990+
extends_ZodType<core.$ZodArrayInternals<T>>,
991991
core.$ZodArray<T>{
992992
element:T;
993993
min(minLength:number,params?:string|core.$ZodCheckMinLengthParams): this;
@@ -1370,7 +1370,7 @@ export function map<Key extends core.SomeType, Value extends core.SomeType>(
13701370

13711371
// ZodSet
13721372
exportinterfaceZodSet<Textendscore.SomeType=core.$ZodType>
1373-
extendsZodType<any,any,core.$ZodSetInternals<T>>,
1373+
extends_ZodType<core.$ZodSetInternals<T>>,
13741374
core.$ZodSet<T>{
13751375
min(minSize:number,params?:string|core.$ZodCheckMinSizeParams): this;
13761376
/** */
@@ -1996,14 +1996,18 @@ export const stringbool: (_params?: string | core.$ZodStringBoolParams) => ZodPi
19961996
)asany;
19971997

19981998
// json
1999-
exporttypeZodJSONSchema=ZodUnion<
1999+
type_ZodJSONSchema=ZodUnion<
20002000
[ZodString,ZodNumber,ZodBoolean,ZodNull,ZodArray<ZodJSONSchema>,ZodRecord<ZodString,ZodJSONSchema>]
2001-
>&{
2002-
_zod:{
2003-
input:util.JSONType;
2004-
output:util.JSONType;
2005-
};
2006-
};
2001+
>;
2002+
type_ZodJSONSchemaInternals=_ZodJSONSchema["_zod"];
2003+
2004+
exportinterfaceZodJSONSchemaInternalsextends_ZodJSONSchemaInternals{
2005+
output:util.JSONType;
2006+
input:util.JSONType;
2007+
}
2008+
exportinterfaceZodJSONSchemaextends_ZodJSONSchema{
2009+
_zod:ZodJSONSchemaInternals;
2010+
}
20072011

20082012
exportfunctionjson(params?:string|core.$ZodCustomParams):ZodJSONSchema{
20092013
constjsonSchema:any=lazy(()=>{
@@ -2016,9 +2020,9 @@ export function json(params?: string | core.$ZodCustomParams): ZodJSONSchema {
20162020
// preprocess
20172021

20182022
// /**@deprecated Use `z.pipe()` and `z.transform()` instead. */
2019-
exportfunctionpreprocess<A,Uextendscore.SomeType>(
2020-
fn:(arg:unknown,ctx:RefinementCtx)=>A,
2023+
exportfunctionpreprocess<A,Uextendscore.SomeType,B=unknown>(
2024+
fn:(arg:B,ctx:RefinementCtx)=>A,
20212025
schema:U
2022-
):ZodPipe<ZodTransform<A,unknown>,U>{
2023-
returnpipe(transform(fnasany),schemaasany);
2026+
):ZodPipe<ZodTransform<A,B>,U>{
2027+
returnpipe(transform(fnasany),schemaasany)asany;
20242028
}

‎packages/zod/src/v4/classic/tests/recursive-types.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ test("mutual recursion with meta", () => {
211211
b:_B;
212212
}>
213213
|undefined;
214+
// | undefined;
214215
type_B=Readonly<{
215216
name:string;
216217
a?:_A;

‎packages/zod/src/v4/core/schemas.ts‎

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,7 @@ export interface $ZodTypeInternals<out O = unknown, out I = unknown> extends _$Z
154154

155155
exporttype$ZodStandardSchema<T>=StandardSchemaV1.Props<core.input<T>,core.output<T>>;
156156

157-
// export interface _$ZodType<T extends _$ZodTypeInternals = _$ZodTypeInternals> {
158-
// _zod: T;
159-
// }
160157
exporttypeSomeType={_zod:_$ZodTypeInternals};
161-
// _$ZodType; //<any, any, $ZodTypeInternals<unknown, unknown>>;
162158

163159
exportinterface$ZodType<
164160
O=unknown,
@@ -168,6 +164,10 @@ export interface $ZodType<
168164
_zod:Internals;
169165
"~standard":$ZodStandardSchema<this>;
170166
}
167+
exportinterface_$ZodType<Textends$ZodTypeInternals=$ZodTypeInternals>
168+
extends$ZodType<T["output"],T["input"],T>{
169+
// _zod: T;
170+
}
171171

172172
exportconst$ZodType:core.$constructor<$ZodType>=/*@__PURE__*/core.$constructor("$ZodType",(inst,def)=>{
173173
inst??={}asany;
@@ -300,8 +300,8 @@ export interface $ZodStringInternals<Input> extends $ZodTypeInternals<string, In
300300
}>;
301301
}
302302

303-
exportinterface$ZodString<Input=unknown>extends$ZodType{
304-
_zod:$ZodStringInternals<Input>;
303+
exportinterface$ZodString<Input=unknown>extends_$ZodType<$ZodStringInternals<Input>>{
304+
//_zod: $ZodStringInternals<Input>;
305305
}
306306

307307
exportconst$ZodString:core.$constructor<$ZodString>=/*@__PURE__*/core.$constructor("$ZodString",(inst,def)=>{
@@ -1463,9 +1463,8 @@ export interface $ZodArrayInternals<T extends SomeType = $ZodType>
14631463
isst:errors.$ZodIssueInvalidType;
14641464
}
14651465

1466-
exportinterface$ZodArray<TextendsSomeType=$ZodType>extends$ZodType{
1467-
_zod:$ZodArrayInternals<T>;
1468-
}
1466+
exportinterface$ZodArray<TextendsSomeType=$ZodType>
1467+
extends$ZodType<core.output<T>[],core.input<T>[],$ZodArrayInternals<T>>{}
14691468

14701469
functionhandleArrayResult(result:ParsePayload<any>,final:ParsePayload<any[]>,index:number){
14711470
if(result.issues.length){
@@ -1524,30 +1523,6 @@ export const $ZodArray: core.$constructor<$ZodArray> = /*@__PURE__*/ core.$const
15241523
////////// //////////
15251524
//////////////////////////////////////////
15261525
//////////////////////////////////////////
1527-
exporttype$ZodShape=Readonly<{[k:string]:$ZodType}>;
1528-
1529-
exportinterface$ZodObjectDef<Shapeextends$ZodShape=$ZodShape>extends$ZodTypeDef{
1530-
type:"object";
1531-
shape:Shape;
1532-
catchall?:$ZodType|undefined;
1533-
}
1534-
1535-
exportinterface$ZodObjectInternals<
1536-
/**@ts-ignore Cast variance */
1537-
outShapeextendsReadonly<$ZodShape>=Readonly<$ZodShape>,
1538-
outConfigextends$ZodObjectConfig=$ZodObjectConfig,
1539-
>extends_$ZodTypeInternals{
1540-
def:$ZodObjectDef<Shape>;
1541-
config:Config;
1542-
isst:errors.$ZodIssueInvalidType|errors.$ZodIssueUnrecognizedKeys;
1543-
propValues:util.PropValues;
1544-
// special keys only used for objects
1545-
// not defined on $ZodTypeInternals (base interface) because it breaks cyclical inference
1546-
// the z.infer<> util checks for these first when extracting inferred type
1547-
output:$InferObjectOutput<Shape,Config["out"]>;
1548-
input:$InferObjectInput<Shape,Config["in"]>;
1549-
}
1550-
exporttype$ZodLooseShape=Record<string,any>;
15511526

15521527
typeOptionalOutSchema={_zod:{optout:"optional"}};
15531528
typeOptionalInSchema={_zod:{optin:"optional"}};
@@ -1656,12 +1631,33 @@ export type $catchall<T extends SomeType> = {
16561631
in:{[k:string]:core.input<T>};
16571632
};
16581633

1634+
exporttype$ZodShape=Readonly<{[k:string]:$ZodType}>;
1635+
1636+
exportinterface$ZodObjectDef<Shapeextends$ZodShape=$ZodShape>extends$ZodTypeDef{
1637+
type:"object";
1638+
shape:Shape;
1639+
catchall?:$ZodType|undefined;
1640+
}
1641+
1642+
exportinterface$ZodObjectInternals<
1643+
/**@ts-ignore Cast variance */
1644+
outShapeextendsReadonly<$ZodShape>=Readonly<$ZodShape>,
1645+
outConfigextends$ZodObjectConfig=$ZodObjectConfig,
1646+
>extends_$ZodTypeInternals{
1647+
def:$ZodObjectDef<Shape>;
1648+
config:Config;
1649+
isst:errors.$ZodIssueInvalidType|errors.$ZodIssueUnrecognizedKeys;
1650+
propValues:util.PropValues;
1651+
output:$InferObjectOutput<Shape,Config["out"]>;
1652+
input:$InferObjectInput<Shape,Config["in"]>;
1653+
}
1654+
exporttype$ZodLooseShape=Record<string,any>;
1655+
16591656
exportinterface$ZodObject<
16601657
/**@ts-ignore Cast variance */
16611658
outShapeextendsReadonly<$ZodShape>=Readonly<$ZodShape>,
16621659
outParamsextends$ZodObjectConfig=$ZodObjectConfig,
16631660
>extends$ZodType<any,any,$ZodObjectInternals<Shape,Params>>{
1664-
// _zod: $ZodObjectInternals<Shape, Params>;
16651661
"~standard":$ZodStandardSchema<this>;
16661662
}
16671663

‎play.ts‎

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,3 @@
11
import{z}from"zod/v4";
22

3-
z.ipv4()
4-
.transform((value)=>{
5-
// Called when invalid value
6-
console.log("input:",value);
7-
8-
returnvalue;
9-
})
10-
.safeParse("invalid_value");
11-
12-
z.email()
13-
.transform((value)=>{
14-
// Called when invalid value
15-
console.log("input:",value);
16-
17-
returnvalue;
18-
})
19-
.safeParse("invalid_value");
20-
21-
z.uuid()
22-
.transform((value)=>{
23-
// Called when invalid value
24-
console.log("input:",value);
25-
26-
returnvalue;
27-
})
28-
.safeParse("invalid_value");
29-
30-
z.url()
31-
.transform((value)=>{
32-
// Not called when invalid value
33-
console.log("input:",value);
34-
returnvalue;
35-
})
36-
.safeParse("invalid_value");
37-
38-
z.number()
39-
.transform((value)=>{
40-
// Not called when invalid value
41-
console.log("input:",value);
42-
43-
returnvalue;
44-
})
45-
.safeParse("invalid_value");
46-
47-
z.boolean()
48-
.transform((value)=>{
49-
// Not called when invalid value
50-
console.log("input:",value);
51-
52-
returnvalue;
53-
})
54-
.safeParse("invalid_value");
3+
z;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp