Skip to content

Commit

Permalink
docs(reference/typescript): remove type provider from typebox example
Browse files Browse the repository at this point in the history
also rephrase some sentences
  • Loading branch information
jscheffner committed Jul 17, 2024
1 parent ba11f46 commit 53afef5
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions docs/Reference/TypeScript.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,24 210,23 @@ And a `zod` wrapper by a third party called [`fastify-type-provider-zod`](https:
They simplify schema validation setup and you can read more about them in [Type
Providers](./Type-Providers.md) page.
Below is how to setup schema validation using _vanilla_ `typebox` and
`json-schema-to-ts` packages.
Below is how to setup schema validation using the `typebox`, `json-schema-to-typescript` and

Check failure on line 213 in docs/Reference/TypeScript.md

View workflow job for this annotation

GitHub Actions / Lint Markdown

Line length [Expected: 80; Actual: 92]
`json-schema-to-ts` packages without type providers.
#### TypeBox
A useful library for building types and a schema at once is
[TypeBox](https://www.npmjs.com/package/@sinclair/typebox) along with
[fastify-type-provider-typebox](https://github.com/fastify/fastify-type-provider-typebox).
[TypeBox](https://www.npmjs.com/package/@sinclair/typebox).
With TypeBox you define your schema within your code and use them
directly as types or schemas as you need them.
When you want to use it for validation of some payload in a fastify route you
can do it as follows:
1. Install `typebox` and `fastify-type-provider-typebox` in your project.
1. Install `typebox` in your project.
```bash
npm i @sinclair/typebox @fastify/type-provider-typebox
npm i @sinclair/typebox
```
2. Define the schema you need with `Type` and create the respective type with
Expand All @@ -248,10 247,9 @@ can do it as follows:
```typescript
import Fastify from 'fastify'
import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox'
// ...
const fastify = Fastify().withTypeProvider<TypeBoxTypeProvider>()
const fastify = Fastify()
fastify.post<{ Body: UserType, Reply: UserType }>(
'/',
Expand All @@ -271,12 269,11 @@ can do it as follows:
)
```
#### Schemas in JSON Files
#### json-schema-to-typescript
In the last example we used interfaces to define the types for the request
querystring and headers. Many users will already be using JSON Schemas to define
these properties, and luckily there is a way to transform existing JSON Schemas
into TypeScript interfaces!
In the last example we used Typebox to define the types and schemas for our route. Many users will already

Check failure on line 274 in docs/Reference/TypeScript.md

View workflow job for this annotation

GitHub Actions / Lint Markdown

Line length [Expected: 80; Actual: 106]
be using JSON Schemas to define these properties, and luckily there is a way to transform existing JSON

Check failure on line 275 in docs/Reference/TypeScript.md

View workflow job for this annotation

GitHub Actions / Lint Markdown

Line length [Expected: 80; Actual: 103]
Schemas into TypeScript interfaces!
1. If you did not complete the 'Getting Started' example, go back and follow
steps 1-4 first.
Expand Down

0 comments on commit 53afef5

Please sign in to comment.