From a037c0867ddbc18a5e5911cbf5b749e7c850713b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Fri, 26 Aug 2022 02:10:11 +0100 Subject: [PATCH] fix(ts): use `AppProps`'s generic for `pageProps` (#38867) Currently, you cannot set `pageProps`'s type when using `AppProps`'s generic, it's always `any`. Before: ![image](https://user-images.githubusercontent.com/18369201/180234440-3b37460c-ff92-413f-9d1c-38e35e35a5b4.png) After: ![image](https://user-images.githubusercontent.com/18369201/180234644-335eec85-0315-4ff8-aba1-53edf0b64e1a.png) ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples) --- packages/next/shared/lib/utils.ts | 8 ++++---- test/integration/app-tree/pages/_app.tsx | 5 +---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/next/shared/lib/utils.ts b/packages/next/shared/lib/utils.ts index 6ec6a7dcc0d56..1e6bb46df7bc0 100644 --- a/packages/next/shared/lib/utils.ts +++ b/packages/next/shared/lib/utils.ts @@ -165,15 +165,15 @@ export type AppContextType = { router: R } -export type AppInitialProps = { - pageProps: any +export type AppInitialProps

= { + pageProps: P } export type AppPropsType< R extends NextRouter = NextRouter, P = {} -> = AppInitialProps & { - Component: NextComponentType +> = AppInitialProps

& { + Component: NextComponentType router: R __N_SSG?: boolean __N_SSP?: boolean diff --git a/test/integration/app-tree/pages/_app.tsx b/test/integration/app-tree/pages/_app.tsx index 78e095ae1a6ca..bcd7a5546e8ab 100644 --- a/test/integration/app-tree/pages/_app.tsx +++ b/test/integration/app-tree/pages/_app.tsx @@ -7,7 +7,7 @@ import { renderToString } from 'react-dom/server' export const DummyContext = createContext(null) -class MyApp

extends App

{ +export default class MyApp extends App<{ html: string }> { static async getInitialProps({ Component, AppTree, ctx }: AppContext) { let pageProps = {} @@ -34,7 +34,6 @@ class MyApp

extends App

{ render() { const { Component, pageProps, html, router } = this.props const href = router.pathname === '/' ? '/another' : '/' - const child = html && router.pathname !== '/hello' ? ( <> @@ -52,5 +51,3 @@ class MyApp

extends App

{ ) } } - -export default MyApp