Unverified Commit a037c086 authored by Balázs Orbán's avatar Balázs Orbán Committed by GitHub

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)
parent d267c300
......@@ -165,15 +165,15 @@ export type AppContextType<R extends NextRouter = NextRouter> = {
router: R
}
export type AppInitialProps = {
pageProps: any
export type AppInitialProps<P = any> = {
pageProps: P
}
export type AppPropsType<
R extends NextRouter = NextRouter,
P = {}
> = AppInitialProps & {
Component: NextComponentType<NextPageContext, any, P>
> = AppInitialProps<P> & {
Component: NextComponentType<NextPageContext, any, any>
router: R
__N_SSG?: boolean
__N_SSP?: boolean
......
......@@ -7,7 +7,7 @@ import { renderToString } from 'react-dom/server'
export const DummyContext = createContext(null)
class MyApp<P = {}> extends App<P & { html: string }> {
export default class MyApp extends App<{ html: string }> {
static async getInitialProps({ Component, AppTree, ctx }: AppContext) {
let pageProps = {}
......@@ -34,7 +34,6 @@ class MyApp<P = {}> extends App<P & { html: string }> {
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<P = {}> extends App<P & { html: string }> {
)
}
}
export default MyApp
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment