Skip to content

Commit

Permalink
chore(gatsby): Add types for getServerData (#34406)
Browse files Browse the repository at this point in the history
* Add types for getServerData

* Add types for getServerData

* Revert get-server-data change

* Make return type a promise

Co-authored-by: Josh <[email protected]>
  • Loading branch information
imjoshin and Josh authored Jan 6, 2022
1 parent 2e32870 commit 183b5f1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/gatsby/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,35 @@ export type PageProps<
serverData: ServerDataType
}

/**
* Props object passed into the [getServerData](https://www.gatsbyjs.com/docs/reference/rendering-options/server-side-rendering/) function.
*/
export type GetServerDataProps = {
headers: Map<string, unknown>
method: string
url: string
query?: Record<string, unknown>
params?: Record<string, unknown>
pageContext: Record<string, unknown>
};

/**
* The return type (promise payload) from the [getServerData](https://www.gatsbyjs.com/docs/reference/rendering-options/server-side-rendering/) function.
*/
export type GetServerDataReturn<ServerDataType = Record<string, unknown>> = Promise<{
headers?: Map<string, unknown>
props?: ServerDataType
status?: number
}>;

/**
* A shorthand type for combining the props and return type for the [getServerData](https://www.gatsbyjs.com/docs/reference/rendering-options/server-side-rendering/) function.
*/
export type GetServerData<ServerDataType> = (props: GetServerDataProps) => GetServerDataReturn<ServerDataType>;

/**
* Constructor arguments for the PageRenderer.
*/
export interface PageRendererProps {
location: WindowLocation
}
Expand Down

0 comments on commit 183b5f1

Please sign in to comment.