From a06b5f042ab1c00f111cddcffd3fdf8d16c482d9 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Mon, 17 Feb 2020 22:47:09 -0500 Subject: [PATCH 1/3] Merge master --- packages/gatsby/index.d.ts | 85 ++++++++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 12 deletions(-) diff --git a/packages/gatsby/index.d.ts b/packages/gatsby/index.d.ts index 6347b49d323d1..5b8372bda4e75 100644 --- a/packages/gatsby/index.d.ts +++ b/packages/gatsby/index.d.ts @@ -29,6 +29,78 @@ export const parsePath: (path: string) => WindowLocation export const prefetchPathname: (path: string) => void +/** + * A props object for adding type safety to your Gatsby pages, can be + * extended with both the query response shape, and the page context. + * + * @example + * // When typing a default page from the ./pages dir + * + * import {PageProps} from "gatsby" + * export default (props: PageProps) => { + * + * @example + * // When adding types for both pageContext and GraphQL query data + * + * import {PageProps} from "gatsby" + * + * type IndexQueryProps = { downloadCount: number } + * type LocaleLookUpInfo = { translationStrings: any } & { langKey: string, slug: string } + * type IndexPageProps = PageProps + * + * export default (props: IndexProps) => { + * .. + */ +export type PageProps = { + /** The path for this current page */ + path: string + /** The URI for the current page */ + uri: string + /** An extended version of window.document which comes from @react/router */ + location: WindowLocation + /** A way to handle programmatically controlling navigation */ + navigate: NavigateFn + "*": string + children: undefined + /** @deprecated use pageContext instead */ + pathContext: object + + pageResources: object + /** + * Data passed into the page via an exported GraphQL query. To set up this type + * you need to use [generics](https://www.typescriptlang.org/play/#example/generic-functions), + * see below for an example + * + * @example + * + * import {PageProps} from "gatsby" + * + * type IndexQueryProps = { downloadCount: number } + * type IndexPageProps = PageProps + * + * export default (props: IndexProps) => { + * .. + * + */ + data: DataType + /** + * A context object which is passed in during the creation of the page. Can be extended if you are using + * `createPage` yourself using generics: + * + * @example + * + * import {PageProps} from "gatsby" + * + * type IndexQueryProps = { downloadCount: number } + * type LocaleLookUpInfo = { translationStrings: any } & { langKey: string, slug: string } + * type IndexPageProps = PageProps + * + * export default (props: IndexProps) => { + * .. + */ + pageContext: PageContextType +} + export interface PageRendererProps { location: WindowLocation } @@ -1206,18 +1278,7 @@ export interface RouteUpdateArgs extends BrowserPluginArgs { } export interface ReplaceComponentRendererArgs extends BrowserPluginArgs { - props: { - path: string - "*": string - uri: string - location: Location - navigate: NavigateFn - children: undefined - pageResources: object - data: object - pageContext: Record - pathContext: Record - } + props: PageProps loader: object } From 3341627d6a94986edb726b7d1de85677ad11b627 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Tue, 18 Feb 2020 09:06:30 -0500 Subject: [PATCH 2/3] Update with feedback from #21542 --- packages/gatsby/index.d.ts | 60 +++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/packages/gatsby/index.d.ts b/packages/gatsby/index.d.ts index 5b8372bda4e75..114b0b74000a8 100644 --- a/packages/gatsby/index.d.ts +++ b/packages/gatsby/index.d.ts @@ -29,25 +29,25 @@ export const parsePath: (path: string) => WindowLocation export const prefetchPathname: (path: string) => void -/** +/** * A props object for adding type safety to your Gatsby pages, can be * extended with both the query response shape, and the page context. - * - * @example + * + * @example * // When typing a default page from the ./pages dir - * + * * import {PageProps} from "gatsby" * export default (props: PageProps) => { - * + * * @example * // When adding types for both pageContext and GraphQL query data - * + * * import {PageProps} from "gatsby" - * + * * type IndexQueryProps = { downloadCount: number } * type LocaleLookUpInfo = { translationStrings: any } & { langKey: string, slug: string } * type IndexPageProps = PageProps - * + * * export default (props: IndexProps) => { * .. */ @@ -57,44 +57,56 @@ export type PageProps - * + * * export default (props: IndexProps) => { * .. - * + * */ data: DataType - /** + /** * A context object which is passed in during the creation of the page. Can be extended if you are using * `createPage` yourself using generics: - * + * * @example - * + * * import {PageProps} from "gatsby" - * + * * type IndexQueryProps = { downloadCount: number } * type LocaleLookUpInfo = { translationStrings: any } & { langKey: string, slug: string } * type IndexPageProps = PageProps - * + * * export default (props: IndexProps) => { * .. */ From f8224f344706717f6707ff509c88b1915649f81b Mon Sep 17 00:00:00 2001 From: Orta Date: Tue, 18 Feb 2020 15:16:49 -0500 Subject: [PATCH 3/3] Update packages/gatsby/index.d.ts Co-Authored-By: Ward Peeters --- packages/gatsby/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby/index.d.ts b/packages/gatsby/index.d.ts index 114b0b74000a8..5f10e6239180b 100644 --- a/packages/gatsby/index.d.ts +++ b/packages/gatsby/index.d.ts @@ -51,7 +51,7 @@ export const prefetchPathname: (path: string) => void * export default (props: IndexProps) => { * .. */ -export type PageProps = { +export type PageProps = { /** The path for this current page */ path: string /** The URI for the current page */