Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(gatsby): add generic to GatsbyFunctionRequest #35029

Merged
merged 6 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/docs/reference/functions/getting-started.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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