Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ts): use AppProps's generic for pageProps #38867

Merged
merged 4 commits into from Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/next/shared/lib/utils.ts
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
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