Skip to content

Commit

Permalink
fix(ts): use AppProps's generic for pageProps (#38867)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
balazsorban44 authored Aug 26, 2022
1 parent d267c30 commit a037c08
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
8 changes: 4 additions & 4 deletions packages/next/shared/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions test/integration/app-tree/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand All @@ -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' ? (
<>
Expand All @@ -52,5 +51,3 @@ class MyApp<P = {}> extends App<P & { html: string }> {
)
}
}

export default MyApp

0 comments on commit a037c08

Please sign in to comment.