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

feat(ts): expose `AppType` (#40391)

An alternative solution to #40371

Ref: #38867, https://github.com/t3-oss/create-t3-app/issues/412,
https://github.com/t3-oss/create-t3-app/pull/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)
parent 6fb1121e
...@@ -5,10 +5,11 @@ import { ...@@ -5,10 +5,11 @@ import {
AppInitialProps, AppInitialProps,
AppPropsType, AppPropsType,
NextWebVitalsMetric, NextWebVitalsMetric,
AppType,
} from '../shared/lib/utils' } from '../shared/lib/utils'
import type { Router } from '../client/router' import type { Router } from '../client/router'
export { AppInitialProps } export { AppInitialProps, AppType }
export { NextWebVitalsMetric } export { NextWebVitalsMetric }
......
...@@ -27,10 +27,10 @@ export type DocumentType = NextComponentType< ...@@ -27,10 +27,10 @@ export type DocumentType = NextComponentType<
DocumentProps DocumentProps
> >
export type AppType = NextComponentType< export type AppType<P = {}> = NextComponentType<
AppContextType, AppContextType,
AppInitialProps, P,
AppPropsType AppPropsType<any, P>
> >
export type AppTreeType = ComponentType< export type AppTreeType = ComponentType<
......
// import App from "next/app"; import type { AppType } from 'next/app'
import type { AppProps /*, AppContext */ } from 'next/app'
function MyApp({ Component, pageProps }: AppProps) { const MyApp: AppType<{ foo: string }> = ({ Component, pageProps }) => {
return <Component {...pageProps} /> return <Component {...pageProps} />
} }
// Only uncomment this method if you have blocking data requirements for MyApp.getInitialProps = () => ({ foo: 'bar' })
// 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 }
// }
export default MyApp 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