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 types for getServerData #34406

Merged
merged 5 commits into from
Jan 6, 2022
Merged
Changes from 4 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
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>> = {
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) => Promise<GetServerDataReturn<ServerDataType>>;
pieh marked this conversation as resolved.
Show resolved Hide resolved

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