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

error Unsafe assignment of an any value #2011

Closed
koji-- opened this issue Aug 3, 2023 · 11 comments
Closed

error Unsafe assignment of an any value #2011

koji-- opened this issue Aug 3, 2023 · 11 comments
Assignees

Comments

@koji--
Copy link

koji-- commented Aug 3, 2023

💥 Regression Report

When update from v22.5.1 to v23.4.1, eslint gives title error.

When embedding a value in the second argument of the t() function, if there was a place where the t() function was used, it seemed to cause an error.

Last working version

Worked up to version: 22.5.1

Stopped working in version: 23.4.1(Probably from 23.0.0)

To Reproduce

Steps to reproduce the behavior:

I am trying in the following environment.

https://github.com/koji--/i18n-test

// is set to v23.4.1 and run eslint
$ yarn eslint
yarn run v1.22.19
$ eslint --ext .ts,tsx ./app

/path/to/i18n-test/app/app.tsx
  22:42  error  Unsafe assignment of an `any` value  @typescript-eslint/no-unsafe-assignment

✖ 1 problem (1 error, 0 warnings)

error Command failed with exit code 1.

// set to v22.5.1
$ yarn add i18next@22.5.1
...

// run eslint again
$ yarn eslint
yarn run v1.22.19
$ eslint --ext .ts,tsx ./app
✨  Done in 2.05s.

Expected behavior

No errors in eslint like it did with v22.5.1.

Your Environment

  • runtime version: node v20.3.1
  • i18next version: v23.4.1
  • os: Mac
@adrai
Copy link
Member

adrai commented Aug 3, 2023

workaraound:

- console.log("hoge: ", i18next.t("d", { val: i18next.t("a") }));
+ console.log("hoge: ", i18next.t("d", { val: i18next.t("a") as string }));

@koji--
Copy link
Author

koji-- commented Aug 3, 2023

@adrai Thank you for reply. It's true that the errors can be resolved with that workaround, but what concerns me is whether the change from string type to any type aligns with the implementer's intention. If this is intentional, it's going to be tough, but I plan to make the necessary adjustments in the parts where i18next is being used. If it's not intentional and can be addressed on the i18next side, I intend to wait for that.

@adrai
Copy link
Member

adrai commented Aug 3, 2023

Need to wait for @pedrodurek feedback

@jwesselink
Copy link

What version of Typescript are you using? Using v5 fixed the error for me (see: #2008)

@koji--
Copy link
Author

koji-- commented Aug 4, 2023

@stale
Copy link

stale bot commented Aug 12, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@adrai adrai added stale and removed stale labels Aug 12, 2023
@stale stale bot added the stale label Aug 12, 2023
@jbanulso
Copy link

jbanulso commented Sep 6, 2023

I'm experiencing a similar issue, with ESLint complaining about using an any value.

Previously I've worked around it by doing t<string>('MY.TRANSLATION.KEY'), but after the upgrade to version 23 I see that is not allowed anymore, getting the same TS error message ("Expected 3-4 type arguments, but got 1") as in issue #2029

EDIT: if it makes a difference, I'm fetching the translations at runtime using i18n-http-backend, so it's not possible for me to hardcode the translations and types during build time.

@stale stale bot removed the stale label Sep 6, 2023
@marcalexiei
Copy link
Member

@koji-- This issue should be now fixed in v23.5.0.
I just finished trying it myself and everything works correctly.

@jbanulso
Copy link

jbanulso commented Sep 7, 2023

I'm still experiencing the same ESLint error with v23.5.0. I realise this GitHub issue was originally about the second argument of the t function, and in my case is just about the t function itself, so please let me know if it'd be better to create a new GitHub issue.

I've tried to recreate a somewhat minimal repro here: https://codesandbox.io/s/pensive-feather-lwwpwz?file=/src/App.tsx:222-270. Unfortunately I haven't managed ESLint to bring the said error forward, but the question remains, why does the result from the t function have any type instead of string?

@koji--
Copy link
Author

koji-- commented Sep 7, 2023

@marcalexiei Thank you. I also solved it with v23.5.0.

@koji--
Copy link
Author

koji-- commented Sep 7, 2023

@jbanulso Actually, I'm having the same error with a different cause.

I'm going to see if I can create an issue for that, but it seems like it would be a good idea for you to create a separate issue as well.

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

No branches or pull requests

6 participants