File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ z.coerce.bigint(); // BigInt(input)
37
37
38
38
The coerced variant of these schemas attempts to convert the input value to the appropriate type.
39
39
40
+
40
41
``` ts
41
42
const schema = z .coerce .string ();
42
43
@@ -46,6 +47,16 @@ schema.parse(true); // => "true"
46
47
schema .parse (null ); // => "null"
47
48
```
48
49
50
+ The input type of these coerced schemas is ` unknown ` by default. To specify a more specific input type, pass a generic parameter:
51
+
52
+ ``` ts
53
+ const A = z .coerce .number ();
54
+ type AInput = z .infer <typeof A >; // => number
55
+
56
+ const B = z .coerce .number <number >();
57
+ type BInput = z .infer <typeof B >; // => number
58
+ ```
59
+
49
60
<Accordions type = " single" ><Accordion title = " How coercion works in Zod" >
50
61
51
62
Zod coerces all inputs using the built-in constructors.
You can’t perform that action at this time.
0 commit comments