Skip to content

Commit

Permalink
docs: fix header and body generic types (#2103)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmazzola committed Feb 18, 2020
1 parent 772cf5e commit 98ca7fd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docs/TypeScript.md
Expand Up @@ -110,8 +110,8 @@ const opts: fastify.RouteShorthandOptions = {
server.get<Query, Params, Headers, Body>('/ping/:bar', opts, (request, reply) => {
console.log(request.query) // this is of type Query!
console.log(request.params) // this is of type Params!
console.log(request.body) // this is of type Body!
console.log(request.headers) // this is of type Headers!
console.log(request.body) // this is of type Body!
reply.code(200).send({ pong: 'it worked!' })
})
```
Expand Down Expand Up @@ -143,8 +143,8 @@ const opts: fastify.RouteShorthandOptions = {
server.get<fastify.DefaultQuery, Params, unknown>('/ping/:bar', opts, (request, reply) => {
console.log(request.query) // this is of type fastify.DefaultQuery!
console.log(request.params) // this is of type Params!
console.log(request.body) // this is of type unknown!
console.log(request.headers) // this is of type fastify.DefaultHeader because typescript will use the default type value!
console.log(request.headers) // this is of type unknown!
console.log(request.body) // this is of type fastify.DefaultBody because typescript will use the default type value!
reply.code(200).send({ pong: 'it worked!' })
})

Expand All @@ -155,8 +155,8 @@ server.get<fastify.DefaultQuery, Params, unknown>('/ping/:bar', opts, (request,
server.get<unknown, Params, unknown, unknown>('/ping/:bar', opts, (request, reply) => {
console.log(request.query) // this is of type unknown!
console.log(request.params) // this is of type Params!
console.log(request.body) // this is of type unknown!
console.log(request.headers) // this is of type unknown!
console.log(request.body) // this is of type unknown!
reply.code(200).send({ pong: 'it worked!' })
})
```
Expand Down

0 comments on commit 98ca7fd

Please sign in to comment.