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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
TS: Can no longer assign translations directly in a setState() after version 12.0.0 bump #1576
Comments
Did you follow: https://www.i18next.com/overview/typescript ? |
Please see this code sandbox triggering the same error: I did indeed read through https://www.i18next.com/overview/typescript. But could unfortunately not find the fix needed for this issue. |
There seems to be an issue with the updated types:
The return value from the |
there are many related issues from people bumped to the version 22, so I'm surprised response is always the same :) |
@pedrodurek is currently the only one trying to investigate and fix those things in his limited time... @kirill-linnik feel free to contribute and help |
Hey @MortenEmde, you need to type augment |
should be fixed with i18next v22.0.5 |
This problem still occurs. i18next 22.0.5 |
I bumped into the issue as well:
I followed the TypeScript definitions as well. |
// i18next.d.ts
import 'i18next';
declare module 'i18next' {
interface CustomTypeOptions {
returnNull: false;
...
}
} I also recommend updating your i18next configuration to behave accordantly. https://www.i18next.com/overview/configuration-options#translation-defaults i18next.init({
returnNull: false,
...
}); |
this fixes the issue for me. This should be urgently mentioned in the documentation (https://www.i18next.com/overview/typescript), as this is the only way to restore the old behavior, and otherwise all react+TypeScript projects are probably unfixable if they don't want to type their keys. |
Maybe I was a bit preemptive at closing this one. |
probably because the translations are not typed.... @pedrodurek ? |
Hey @MortenEmde, you need to either, include "include": [
"./src/**/*",
"./i18next.d.ts"
], or move the https://codesandbox.io/s/i18next-translation-in-setstate-forked-iyhgch?file=/tsconfig.json:6-72 |
馃悰 Bug Report
Prior to v12.0.0 we could assign our translation directly to a setState of the use state hook like so:
After the version bump from v11 to v12 we unfortunately face the below error:
Argument of type 'DefaultTFuncReturn' is not assignable to parameter of type 'SetStateAction<string>'.
To Reproduce
Expected behavior
I would expect to be able to pass the TFunction directly to a setStateAction as in previous version.
We have found a workaround where can remove the error by wrapping the TFunction in a template string like so:
Is this now the intended way to pass translations to a setState hook after the latest type safety improvements?
Please feel free to point me towards the new documentation about hook interaction in case I missed it.
Your Environment
The text was updated successfully, but these errors were encountered: