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
ESLint error: Unsafe assignment of an any
value
#2032
Comments
I suspect, this is because @marcalexiei forgot to change also the types for typescript v4 with #2018 |
beside that, I have no idea, why sometimes it's any and sometimes string |
@adrai sorry for the confusion, I'm using Typescript v5 in my codebase but I see now I had v4 in the codesandbox, I have corrected that. |
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. |
Having the same issue, using i18next 23.5.1 Update: Using Typescript v5 fixes the issue |
@jbanulso, are you still facing the reported issue? |
@pedrodurek unfortunately yes |
the same error
error must 3 declarete |
Maybe face the same question. Some of my i18n resources are static and stored in the front-end project, and the others are stored in the backend, and I will store the key at the same time. For me, in my code: const { t } = useTranslation()
t(key) If I use the key, a variable from backend api, it cannot satisfy the type definition in the front-end project. |
💥 Regression Report
Related to #2011.
Since v22.5.0, ESLint started to complain about using an
any
value as the returned result from thet()
function. Please note that for some reason this does not happen everywhere thet
function is used, just in some specific instances (haven't managed to find a pattern or the culprit though).Previously I've worked around this issue by doing
t<string>('MY.TRANSLATION.KEY')
, but after the upgrade to v23.5.0 I see that is not allowed anymore, getting the same TS error message ("Expected 3-4 type arguments, but got 1") as in issue #2029In case 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.Last working version
Worked up to version: with my
t<string>
workaround, 22.5.0 - without any workarounds this started happening in v21 I believe.Stopped working in version: 23.0.0
To Reproduce
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?
Expected behavior
At least being able to use the
t<string>
workaround. Ideally, that the return type from thet
function is consistentlystring
, instead of varying betweenstring
andany
Your Environment
The text was updated successfully, but these errors were encountered: