useflyyer / next-rosetta

Next.js + Rosetta + TypeScript with native i18n support | Lightweight, simple, easy to integrate, no custom server required and efficient because will only download the locale you need.
https://next-rosetta.vercel.app
MIT License
64 stars 4 forks source link

Property 'table' does not exist on type '{}' #43

Open AimanAlmureish opened 1 year ago

AimanAlmureish commented 1 year ago

I am trying to implement it on a Next js project and I get the following error in the _app.tsx


import { I18nProvider } from "next-rosetta";
import type { ReactElement, ReactNode } from "react";
import type { NextPage } from "next";
import { AppProps } from "next/app";
import Layout from "../components/layout/layout";
import "../styles/globals.css";
import "../styles/kvass.min.css";

export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
  getLayout?: (page: ReactElement) => ReactNode;
};

type AppPropsWithLayout = AppProps & {
  Component: NextPageWithLayout;
};

function MyApp({ Component, pageProps }: AppPropsWithLayout) {
  const getLayout = Component.getLayout ?? ((page) => page);

  return (
    <I18nProvider table={pageProps.table}>
      {getLayout(<Component {...pageProps} />)}
    </I18nProvider>
  );
}

export default MyApp;

The pageProps.table is showing this error Property 'table' does not exist on type '{}'

AimanAlmureish commented 1 year ago

Any ideas on how to fix it?

lopezjurip commented 1 year ago

Try this:

UPDATED

import type { AppProps } from "next/app";
import { type I18nProps, I18nProvider } from "next-rosetta";

import type { MyLocale } from "../i18n";

export default function App({ Component, pageProps }: AppProps<I18nProps<MyLocale>>) {
  return (
    <I18nProvider table={pageProps.table}>
      ...
    </I18nProvider>
  );
}
AimanAlmureish commented 1 year ago

So sorry for the late response! With my code I get this now Type 'AppPropsWithLayout' is not generic.ts(2315)

This is because I am using the layout. Any fixes for this?