Skip to content

Commit

Permalink
chore(gatsby): add generic to GatsbyFunctionRequest (#35029)
Browse files Browse the repository at this point in the history
Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com>
Co-authored-by: Lennart <lekoarts@gmail.com>
  • Loading branch information
3 people committed Mar 14, 2022
1 parent c5b8bb9 commit bf8392c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions docs/docs/reference/functions/getting-started.md
Expand Up @@ -48,11 +48,15 @@ Functions can be written in JavaScript or Typescript.
```ts:title=src/api/typescript.ts
import { GatsbyFunctionRequest, GatsbyFunctionResponse } from "gatsby"

interface ContactBody {
message: string
}

export default function handler(
req: GatsbyFunctionRequest,
req: GatsbyFunctionRequest<ContactBody>,
res: GatsbyFunctionResponse
) {
res.send(`I am TYPESCRIPT`)
res.send({ title: `I am TYPESCRIPT`, message: req.body.message })
}
```

Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby/index.d.ts
Expand Up @@ -1648,7 +1648,7 @@ export interface GatsbyFunctionResponse<T = any> extends ServerResponse {
/**
* Gatsby function route request
*/
export interface GatsbyFunctionRequest extends IncomingMessage {
export interface GatsbyFunctionRequest<ReqBody = any> extends IncomingMessage {
/**
* Object of values from URL query parameters (after the ? in the URL)
*/
Expand All @@ -1658,7 +1658,7 @@ export interface GatsbyFunctionRequest extends IncomingMessage {
* Object of values from route parameters
*/
params: Record<string, string>
body: any
body: ReqBody
/**
* Object of `cookies` from header
*/
Expand Down

0 comments on commit bf8392c

Please sign in to comment.