diff --git a/website/src/routes/guides/(migration)/migrate-from-zod/index.mdx b/website/src/routes/guides/(migration)/migrate-from-zod/index.mdx index 7378a77ba..eae58eefb 100644 --- a/website/src/routes/guides/(migration)/migrate-from-zod/index.mdx +++ b/website/src/routes/guides/(migration)/migrate-from-zod/index.mdx @@ -53,6 +53,8 @@ const value = z.string().parse('foo'); const value = v.parse(v.string(), 'foo'); ``` +We recommend that you read our mental model guide to understand how the individual functions of Valibot's modular API work together. + ## Change names Most of the names are the same as in Zod. However, there are some exceptions. The following table shows all names that have changed. @@ -92,6 +94,7 @@ Most of the names are the same as in Zod. However, there are some exceptions. Th | `shape` | `entries` | | `strict` | `strictObject` | | `strip` | `object` | +| `superRefine` | `rawCheck`, `rawTransform` | ## Other details @@ -138,6 +141,12 @@ const NumberSchema = z.coerce.number(); const NumberSchema = v.pipe(v.unknown(), v.transform(Number)); ``` +Instead of `unknown` as in the previous example, we usually recommend using a specific schema such as `string` to improve type safety. This allows you, for example, to validate the formatting of the string with `decimal` before transforming it to a number. + +```ts +const NumberSchema = v.pipe(v.string(), v.decimal(), v.transform(Number)); +``` + ### Async validation Similar to Zod, Valibot supports synchronous and asynchronous validation. However, the API is a little bit different. See the async guide for more details.