Skip to content

Commit bf8392c

Browse files
mckelveygreggatsbybotLekoArts
authored
chore(gatsby): add generic to GatsbyFunctionRequest (#35029)
Co-authored-by: gatsbybot <[email protected]> Co-authored-by: Lennart <[email protected]>
1 parent c5b8bb9 commit bf8392c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

docs/docs/reference/functions/getting-started.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,15 @@ Functions can be written in JavaScript or Typescript.
4848
```ts:title=src/api/typescript.ts
4949
import { GatsbyFunctionRequest, GatsbyFunctionResponse } from "gatsby"
5050

51+
interface ContactBody {
52+
message: string
53+
}
54+
5155
export default function handler(
52-
req: GatsbyFunctionRequest,
56+
req: GatsbyFunctionRequest<ContactBody>,
5357
res: GatsbyFunctionResponse
5458
) {
55-
res.send(`I am TYPESCRIPT`)
59+
res.send({ title: `I am TYPESCRIPT`, message: req.body.message })
5660
}
5761
```
5862

packages/gatsby/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ export interface GatsbyFunctionResponse<T = any> extends ServerResponse {
16481648
/**
16491649
* Gatsby function route request
16501650
*/
1651-
export interface GatsbyFunctionRequest extends IncomingMessage {
1651+
export interface GatsbyFunctionRequest<ReqBody = any> extends IncomingMessage {
16521652
/**
16531653
* Object of values from URL query parameters (after the ? in the URL)
16541654
*/
@@ -1658,7 +1658,7 @@ export interface GatsbyFunctionRequest extends IncomingMessage {
16581658
* Object of values from route parameters
16591659
*/
16601660
params: Record<string, string>
1661-
body: any
1661+
body: ReqBody
16621662
/**
16631663
* Object of `cookies` from header
16641664
*/

0 commit comments

Comments
 (0)