Skip to content

Instantly share code, notes, and snippets.

@delvedor
Created January 6, 2022 09:11
Show Gist options
  • Save delvedor/fd9b55c7acc7343796af6ea0c51a297f to your computer and use it in GitHub Desktop.
Save delvedor/fd9b55c7acc7343796af6ea0c51a297f to your computer and use it in GitHub Desktop.
import Fastify from 'fastify'
import { TypeBoxTypeProvider, Type } from 'fastify-type-provider-typebox'
const fastify = Fastify({
ajv: {
customOptions: {
strict: 'log',
keywords: ['kind', 'modifier']
}
}
}).withTypeProvider<TypeBoxTypeProvider>()
fastify.route({
method: 'GET',
path: '/route',
schema: {
querystring: Type.Object({
foo: Type.Number(),
bar: Type.String()
})
},
handler: (request, reply) => {
// type Query = { foo: number, bar: string }
const { foo, bar } = request.query // type safe!
}
})
@adbutterfield
Copy link

adbutterfield commented Jun 15, 2022

I think:

import { TypeBoxTypeProvider, Type } from 'fastify-type-provider-typebox'

should be:

import { TypeBoxTypeProvider, Type } from '@fastify/type-provider-typebox'

Also Type isn't used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment