amannn / next-intl

🌐 Internationalization (i18n) for Next.js
https://next-intl-docs.vercel.app
MIT License
2.58k stars 236 forks source link

`t.rich` return type has become wrong when using it in Next v15 projects together with the new React v19 types #1440

Closed ChristianIvicevic closed 3 weeks ago

ChristianIvicevic commented 3 weeks ago

Description

After attempting to migrate to Next v15 I noticed a false positive during linting causing linting to fail and I narrowed it down to t.rich behaving differently in terms of types. Without looking into the implementation details it feels like that t.rich relies on some React specific types that were changed in v19.

Verifications

Mandatory reproduction URL

https://github.com/ChristianIvicevic/next-intl-bug-repro-app-router/tree/next-15

Reproduction description

Steps to reproduce:

  1. Open reproduction which is in the next-15 branch (that is the result of applying the codemod from Next v15 onto the main branch of the reproduction, refer to the commit)
  2. Open app/[locale]/page.tsx in your editor
  3. See error: t.rich returns any
CleanShot 2024-10-22 at 18 45 58@2x

Expected behaviour

In the main branch of the same reproduction you will notice how t.rich is correctly typed and returns string | ReactElement | ReactNodeArray as expected. It being any in the reproduction causes eslint to complain with the no-unsafe-return error.

CleanShot 2024-10-22 at 18 46 57@2x CleanShot 2024-10-22 at 18 48 19@2x
amannn commented 3 weeks ago

Thanks for the careful reproduction! 🙏

I've opened https://github.com/amannn/next-intl/pull/1445 to address this.

As a side note, if you consider upgrading to Next.js 15 already, you might want to consider https://github.com/amannn/next-intl/issues/1442.

ChristianIvicevic commented 3 weeks ago

Thanks for looking into it! Regarding your warning, I don't use i18n routing anyways, so one less thing to keep track of when migrating.