From d2934b77163d6ff55516ecd29eeb61ab2d32601c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Fri, 9 Sep 2022 12:55:26 +0200 Subject: [PATCH 1/3] feat(ts): expose `AppType` --- packages/next/pages/_app.tsx | 3 ++- packages/next/shared/lib/utils.ts | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/next/pages/_app.tsx b/packages/next/pages/_app.tsx index 691555628145..c646d0842fea 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 ec5197e0c3b9..e239d0a44a9d 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 + AppInitialProps

, + AppPropsType > export type AppTreeType = ComponentType< From ca9431eeff268f84803eaa301bd83db4e08b4dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Fri, 9 Sep 2022 13:06:14 +0200 Subject: [PATCH 2/3] fix `getInitialProps` type with `AppType` --- packages/next/shared/lib/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/next/shared/lib/utils.ts b/packages/next/shared/lib/utils.ts index e239d0a44a9d..76b9eee3a520 100644 --- a/packages/next/shared/lib/utils.ts +++ b/packages/next/shared/lib/utils.ts @@ -29,8 +29,8 @@ export type DocumentType = NextComponentType< export type AppType

= NextComponentType< AppContextType, - AppInitialProps

, - AppPropsType + P, + AppPropsType > export type AppTreeType = ComponentType< From 9a20632a67be361abd11de5c10ce55bfa73a98a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Fri, 9 Sep 2022 13:12:42 +0200 Subject: [PATCH 3/3] add test for `AppType` --- test/integration/typescript/pages/_app.tsx | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/test/integration/typescript/pages/_app.tsx b/test/integration/typescript/pages/_app.tsx index bc26412e55da..adc878fa93ec 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