From 2eed498593e6bb0b12eb470be408a5b5fb6a8d79 Mon Sep 17 00:00:00 2001 From: Vitaly Budovski Date: Tue, 24 Dec 2024 18:04:39 +1100 Subject: [PATCH] doc: Document Infer type --- .../content/docs/reference/Schema/common.mdx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/paseri-docs/src/content/docs/reference/Schema/common.mdx b/paseri-docs/src/content/docs/reference/Schema/common.mdx index 41bf7ab..e384d1f 100644 --- a/paseri-docs/src/content/docs/reference/Schema/common.mdx +++ b/paseri-docs/src/content/docs/reference/Schema/common.mdx @@ -97,3 +97,22 @@ if (result.ok) { // result.value is of type `bigint`. } ``` + +## Types + +### `Infer` + +You can use the `Infer` type to determine the result type of any schema. This is useful, because you don't want to +manually define a type that could easily get out of sync with the schema definition. + +```typescript +import * as p from '@vbudovski/paseri'; + +const schema = p.object({ + foo: p.string(), + bar: p.number(), +}) + +type MySchema = p.Infer; +// MySchema will be { foo: string, bar: number }. +```