Skip to content

Commit

Permalink
feat(ts): expose AppType (#40391)
Browse files Browse the repository at this point in the history
An alternative solution to #40371

Ref: #38867, t3-oss/create-t3-app#412,
t3-oss/create-t3-app#414

## 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 committed Sep 9, 2022
1 parent 6fb1121 commit 8bc587a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
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

0 comments on commit 8bc587a

Please sign in to comment.