QuiiBz / next-international

Type-safe internationalization (i18n) for Next.js
https://next-international.vercel.app
MIT License
1.25k stars 59 forks source link

getLocaleProps gives any types for getServerSideProps context #233

Closed mamlzy closed 10 months ago

mamlzy commented 11 months ago

Describe the bug getLocaleProps does not give the proper types. Am i doing something wrong here?

image

About (please complete the following information):

QuiiBz commented 11 months ago

You have to manually type ctx, because we don't know if it's being used with getServerSideProps or getStaticProps:

export const getServerSideProps = getLocaleProps(async (ctx: GetServerSidePropsContext) => {
  return {
    props: {},
  };
});
mamlzy commented 10 months ago

You have to manually type ctx, because we don't know if it's being used with getServerSideProps or getStaticProps:

export const getServerSideProps = getLocaleProps(async (ctx: GetServerSidePropsContext) => {
  return {
    props: {},
  };
});

okay that code is working fine, but @QuiiBz can you give me an example to fix this type error, it's happen when i'm using satisfies GetServerSideProps<Props>. i just want to follow the nextjs docs example.

image
QuiiBz commented 10 months ago

Works fine on my side, the id you're returning is a number instead of a string as specified in HomeProps:

export const getServerSideProps = getLocaleProps(async (ctx: GetServerSidePropsContext) => {
  return {
    props: {
      id: '1',
    },
  };
}) satisfies GetServerSideProps<HomeProps>;
mamlzy commented 10 months ago

Works fine on my side, the id you're returning is a number instead of a string as specified in HomeProps:

export const getServerSideProps = getLocaleProps(async (ctx: GetServerSidePropsContext) => {
  return {
    props: {
      id: '1',
    },
  };
}) satisfies GetServerSideProps<HomeProps>;

oh sorry i didn't see that, thank you for your response😁