Skip to content

Commit 183b5f1

Browse files
imjoshinJosh
and
Josh
authored
chore(gatsby): Add types for getServerData (#34406)
* Add types for getServerData * Add types for getServerData * Revert get-server-data change * Make return type a promise Co-authored-by: Josh <[email protected]>
1 parent 2e32870 commit 183b5f1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

packages/gatsby/index.d.ts

+29
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,35 @@ export type PageProps<
146146
serverData: ServerDataType
147147
}
148148

149+
/**
150+
* Props object passed into the [getServerData](https://www.gatsbyjs.com/docs/reference/rendering-options/server-side-rendering/) function.
151+
*/
152+
export type GetServerDataProps = {
153+
headers: Map<string, unknown>
154+
method: string
155+
url: string
156+
query?: Record<string, unknown>
157+
params?: Record<string, unknown>
158+
pageContext: Record<string, unknown>
159+
};
160+
161+
/**
162+
* The return type (promise payload) from the [getServerData](https://www.gatsbyjs.com/docs/reference/rendering-options/server-side-rendering/) function.
163+
*/
164+
export type GetServerDataReturn<ServerDataType = Record<string, unknown>> = Promise<{
165+
headers?: Map<string, unknown>
166+
props?: ServerDataType
167+
status?: number
168+
}>;
169+
170+
/**
171+
* 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.
172+
*/
173+
export type GetServerData<ServerDataType> = (props: GetServerDataProps) => GetServerDataReturn<ServerDataType>;
174+
175+
/**
176+
* Constructor arguments for the PageRenderer.
177+
*/
149178
export interface PageRendererProps {
150179
location: WindowLocation
151180
}

0 commit comments

Comments
 (0)