fastify / fastify/help

Extract typings generated by type providers

Open
#947 1 comment 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
No language data
Stars
68
Forks
8
Avg merge
11h 2m
Merged PRs (30d)
2

Description

regarding to [Fastify docs](https://fastify.dev/docs/latest/Reference/Type-Providers) you can use `@fastify/type-provider-json-schema-to-ts` to convert the schema into a TS type, like this:
```
import { JsonSchemaToTsProvider } from '@fastify/type-provider-json-schema-to-ts'
import fastify from 'fastify'
const server = fastify().withTypeProvider()

server.get('/', {schema: /* your schema*/}, (req, res)=>{
// now req.body has the right type
})
```

but, if I want to separate the route logic,.
unfortunately, there is no working example
```
server.get('/', {schema: /* your schema*/}, route)

function route(req, res){
// I want to use the generated type here
let { invalidProp } = req.body
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.