From 8bc587aa30099bdf3ee379fe0b1a2fe3387801cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Fri, 9 Sep 2022 22:32:58 +0200 Subject: [PATCH] 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) --- packages/next/pages/_app.tsx | 3 ++- packages/next/shared/lib/utils.ts | 6 +++--- test/integration/typescript/pages/_app.tsx | 17 +++-------------- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/packages/next/pages/_app.tsx b/packages/next/pages/_app.tsx index 691555628145f5f..c646d0842fea09e 100644 --- a/packages/next/pages/_app.tsx +++ b/packages/next/pages/_app.tsx @@ -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 } diff --git a/packages/next/shared/lib/utils.ts b/packages/next/shared/lib/utils.ts index ec5197e0c3b9a80..76b9eee3a5207d9 100644 --- a/packages/next/shared/lib/utils.ts +++ b/packages/next/shared/lib/utils.ts @@ -27,10 +27,10 @@ export type DocumentType = NextComponentType< DocumentProps > -export type AppType = NextComponentType< +export type AppType

= NextComponentType< AppContextType, - AppInitialProps, - AppPropsType + P, + AppPropsType > export type AppTreeType = ComponentType< diff --git a/test/integration/typescript/pages/_app.tsx b/test/integration/typescript/pages/_app.tsx index bc26412e55dae24..adc878fa93ecd44 100644 --- a/test/integration/typescript/pages/_app.tsx +++ b/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 } -// 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