From 08c7b3d0eb2ced622cdd3c4d14a3958ac8161cb8 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Wed, 21 Sep 2022 12:20:18 +0200 Subject: fix(types): add custom types to pageProps with translation --- src/pages/_app.tsx | 5 +++-- src/ts/types/app.ts | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 5bc9f85..ec5dab7 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -11,13 +11,14 @@ const App = ({ Component, pageProps }: AppPropsWithLayout) => { const { locale, defaultLocale } = useRouter(); const appLocale: string = locale || settings.locales.defaultLocale; const getLayout = Component.getLayout ?? ((page) => page); + const { translation, ...componentProps } = pageProps; return ( { enableSystem={true} > - {getLayout(, {})} + {getLayout(, {})} diff --git a/src/ts/types/app.ts b/src/ts/types/app.ts index c11c31b..64bb3af 100644 --- a/src/ts/types/app.ts +++ b/src/ts/types/app.ts @@ -1,6 +1,7 @@ import { NextPage } from 'next'; -import { AppProps } from 'next/app'; +import { AppProps as NextAppProps } from 'next/app'; import { ReactElement, ReactNode } from 'react'; +import { MessageFormatElement } from 'react-intl'; export type NextPageWithLayoutOptions = { withExtraPadding?: boolean; @@ -15,7 +16,16 @@ export type NextPageWithLayout = NextPage & { ) => ReactNode; }; -export type AppPropsWithLayout = AppProps & { +// modified version - allows for custom pageProps type, falling back to 'any' +type AppProps

= { + pageProps: P; +} & Omit, 'pageProps'>; + +type CustomPageProps = { + translation: Record | Record; +}; + +export type AppPropsWithLayout = AppProps & { Component: NextPageWithLayout; }; -- cgit v1.2.3