What TypeScript type should NextJS _app.tsx Component and pageProps be?

The built-in AppProps type is now generic. To use your custom PageProps just pass it into the AppProps type:

import { AppProps } from 'next/app';

interface CustomPageProps { // <--- your custom page props
   // your props
}

function MyApp({ Component, pageProps }: AppProps<CustomPageProps>) {
                                             //   ^^^ use your custom props here
  return <Component {...pageProps} />
                    // ^^^^^ pageProps is now typeof CustomPageProps
}

Leave a Comment

tech