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

feat(ts): expose AppType #40391

Merged
merged 4 commits into from Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion packages/next/pages/_app.tsx
Expand Up @@ -5,10 +5,11 @@ import {
AppInitialProps,
AppPropsType,
NextWebVitalsMetric,
AppType,
} from '../shared/lib/utils'
import type { Router } from '../client/router'

export { AppInitialProps }
export { AppInitialProps, AppType }

export { NextWebVitalsMetric }

Expand Down
6 changes: 3 additions & 3 deletions packages/next/shared/lib/utils.ts
Expand Up @@ -27,10 +27,10 @@ export type DocumentType = NextComponentType<
DocumentProps
>

export type AppType = NextComponentType<
export type AppType<P = {}> = NextComponentType<
AppContextType,
AppInitialProps,
AppPropsType
P,
AppPropsType<any, P>
>

export type AppTreeType = ComponentType<
Expand Down
17 changes: 3 additions & 14 deletions test/integration/typescript/pages/_app.tsx
@@ -1,20 +1,9 @@
// import App from "next/app";
import type { AppProps /*, AppContext */ } from 'next/app'
import type { AppType } from 'next/app'

function MyApp({ Component, pageProps }: AppProps) {
const MyApp: AppType<{ foo: string }> = ({ Component, pageProps }) => {
return <Component {...pageProps} />
}

// Only uncomment this method if you have blocking data requirements for
// every single page in your application. This disables the ability to
// perform automatic static optimization, causing every page in your app to
// be server-side rendered.
//
// MyApp.getInitialProps = async (appContext: AppContext) => {
// // calls page's `getInitialProps` and fills `appProps.pageProps`
// const appProps = await App.getInitialProps(appContext);

// return { ...appProps }
// }
MyApp.getInitialProps = () => ({ foo: 'bar' })

export default MyApp