Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useTranslation hook with Typescript issue #72

Closed
paulconlin opened this issue Feb 13, 2020 · 9 comments
Closed

useTranslation hook with Typescript issue #72

paulconlin opened this issue Feb 13, 2020 · 9 comments

Comments

@paulconlin
Copy link

I'm currently using i18next v19.1.0 and react-i18next 11.3.1 with Typescript v3.7.2

When passing in a string key to the t function from useTranslation(), it keeps saying -

Expected 0 arguments, but got 1.

image

I feel like I might just be missing something basic. Any ideas?

@paulconlin
Copy link
Author

Found the issue, apologies

@LoLei
Copy link

LoLei commented Nov 10, 2023

I'm currently facing the same issue (only in Docker though, for some reason.)

Could you share your solution, please? 🙂

@riccardolardi
Copy link

riccardolardi commented Nov 11, 2023

Same issue, @LoLei found any solution yet? I get the error only when building the Nextjs project, not in dev-mode though.

@riccardolardi
Copy link

Just figured out downgrading i18next to 23.6.0 will get rid of the issue.

@LoLei
Copy link

LoLei commented Nov 13, 2023

@riccardolardi

I think I solved my case as well, first, to fix it in general, apply this solution: i18next/react-i18next#1601 (comment)

The reason why it happens only in Docker, seems to be the version of yarn, at least for me.

Docker images of node ship with yarn version 1 by default.

Running yarn set version stable (version 3 or 4 is fine) and then re-installing the dependencies with yarn install and rebuilding the project fixes it in Docker for me as well.

@1020850886
Copy link

When I upgraded from 23.4.0 to 23.4.1, this error occurred in all places where the t function was used. How can I fix it? @LoLei @riccardolardi @paulconlin

@vizzyo
Copy link

vizzyo commented Dec 9, 2024

i got the same error:
image

    "i18next": "^24.0.5",
    "jshashes": "^1.0.8",
    "lodash.get": "^4.4.2",
    "miniprogram-ci": "2.0.9",
    "react": "^18.1.0",
    "react-dom": "^18.1.0",
    "react-i18next": "^15.1.3",
    "typescript": "^4.1.0",
    ```

@xpioneer
Copy link

xpioneer commented Dec 19, 2024

I encountered the following TypeScript error during compilation:

ERROR in ./src/pages/login/index.tsx:39:19
TS2554: Expected 0 arguments, but got 1.
37 | useEffect(() => {
38 | const typed = new Typed(el.current, {

39 | strings: [t('introduction')],
| ^^^^^^^^^^^^^^
40 | startDelay: 200,
41 | typeSpeed: 50,
42 | loop: true,

Here's my package.json:

"i18next": "^24.1.2",
"react-i18next": "^15.2.0",
"typescript": "^4.9.5",

I upgraded TypeScript to:

"typescript": "^5.7.2",

After the upgrade, the error was resolved.


Analysis:

  1. The error occurs because TypeScript 4.9.x's type inference for react-i18next's useTranslation and its t function does not align perfectly with i18next v24.1.2.
  2. Upgrading TypeScript to 5.7.2 resolves the issue, likely due to improved type inference or updates in handling react-i18next's type definitions.

Solution:

If you encounter this issue, upgrading TypeScript to 5.x or later should resolve it. Alternatively, you could suppress the error by explicitly typing t or updating your type definitions, though upgrading is the most straightforward solution.

@woowalker
Copy link

I encountered the following TypeScript error during compilation:

ERROR in ./src/pages/login/index.tsx:39:19 TS2554: Expected 0 arguments, but got 1. 37 | useEffect(() => { 38 | const typed = new Typed(el.current, {

39 | strings: [t('introduction')],
| ^^^^^^^^^^^^^^
40 | startDelay: 200,
41 | typeSpeed: 50,
42 | loop: true,

Here's my package.json:

"i18next": "^24.1.2", "react-i18next": "^15.2.0", "typescript": "^4.9.5",

I upgraded TypeScript to:

"typescript": "^5.7.2",

After the upgrade, the error was resolved.

Analysis:

  1. The error occurs because TypeScript 4.9.x's type inference for react-i18next's useTranslation and its t function does not align perfectly with i18next v24.1.2.
  2. Upgrading TypeScript to 5.7.2 resolves the issue, likely due to improved type inference or updates in handling react-i18next's type definitions.

Solution:

If you encounter this issue, upgrading TypeScript to 5.x or later should resolve it. Alternatively, you could suppress the error by explicitly typing t or updating your type definitions, though upgrading is the most straightforward solution.

save my life

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants