Skip to content

Commit

Permalink
Improve styling
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin McDonnell committed May 12, 2022
1 parent 6bf9ea7 commit 4628c35
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
39 changes: 19 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ type myFunction = z.infer<typeof myFunction>;
// => ()=>unknown
```

**Define inputs and output**
Define inputs and outputs.

```ts
const myFunction = z
Expand All @@ -1268,24 +1268,6 @@ type myFunction = z.infer<typeof myFunction>;
// => (arg0: string, arg1: number)=>boolean
```

**Extract the input and output schemas**
You can extract the parameters and return type of a function schema.

```ts
myFunction.parameters();
// => ZodTuple<[ZodString, ZodNumber]>

myFunction.returnType();
// => ZodBoolean
```

<!-- `z.function()` accepts two arguments:
* `args: ZodTuple` The first argument is a tuple (created with `z.tuple([...])` and defines the schema of the arguments to your function. If the function doesn't accept arguments, you can pass an empty tuple (`z.tuple([])`).
* `returnType: any Zod schema` The second argument is the function's return type. This can be any Zod schema. -->

> You can use the special `z.void()` option if your function doesn't return anything. This will let Zod properly infer the type of void-returning functions. (Void-returning functions actually return undefined.)
<!--
``` ts
Expand Down Expand Up @@ -1314,7 +1296,9 @@ trimmedLength("sandwich"); // => 8
trimmedLength(" asdf "); // => 4
```

If you only care about validating inputs, that's fine:
If you only care about validating inputs, just don't call the `.returns()` method. The output type will be inferred from the implementation.

> You can use the special `z.void()` option if your function doesn't return anything. This will let Zod properly infer the type of void-returning functions. (Void-returning functions actually return undefined.)
```ts
const myFunction = z
Expand All @@ -1326,6 +1310,21 @@ const myFunction = z
myFunction; // (arg: string)=>number[]
```

Extract the input and output schemas from a function schema.

```ts
myFunction.parameters();
// => ZodTuple<[ZodString, ZodNumber]>

myFunction.returnType();
// => ZodBoolean
```

<!-- `z.function()` accepts two arguments:
* `args: ZodTuple` The first argument is a tuple (created with `z.tuple([...])` and defines the schema of the arguments to your function. If the function doesn't accept arguments, you can pass an empty tuple (`z.tuple([])`).
* `returnType: any Zod schema` The second argument is the function's return type. This can be any Zod schema. -->

## Preprocess

Typically Zod operates under a "parse then transform" paradigm. Zod validates the input first, then passes it through a chain of transformation functions. (For more information about transforms, read the [.transform docs](#transform).)
Expand Down
7 changes: 4 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
}
.markdown-section h2 {
padding: 40px 0px 10px 0px;
border-bottom: 1px solid #dbdbdb;
}

.markdown-section h3 {
padding: 15px 0px 10px 0px;
padding-top: 15px;
}
.markdown-section h4 {
padding: 15px 0px 5px 0px;
.markdown-section h3 code {
font-size: 80%;
}
</style>
</head>
Expand Down

0 comments on commit 4628c35

Please sign in to comment.