-
-
Notifications
You must be signed in to change notification settings - Fork 763
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
Typing error with React 18 #1817
Comments
Typings for the |
For tracking : i18next/react-i18next#1483 |
@azuken would such a TypeScript option like |
@adrai Since it seems that there is no better solution, yeah it would be great to have this in this package. |
fyi: allowObjectInHTMLChildren was already introduced in react-i18next, so you might just update your dependencies |
@adrai this is just what I've done and I have no such option in Trans component. I'm importing component from next-i18next, not react-i18next |
you might need to delete your node_modules folder... react-i18next is a dependency of next-i18next |
This is what I'm doing everytime I update packages.
My code : <Trans i18nKey="subscribe.freeDays" allowObjectInHTMLChildren={true}>
You get
<span className="family-bold">{{ freeDays }}</span>
starting today
</Trans> |
I'm not a TypeScrirpt user, but allowObjectInHTMLChildren is not a Trans prop, but should probably be used like this: https://github.com/i18next/react-i18next/blob/master/ts4.1/index.d.ts#L29 @pedrodurek correct me if I'm wrong |
yeah @adrai, that's correct! |
@adrai I see no usage example in your link, just interface. I do not understand how to implement this option. |
Do you mean this? https://react.i18next.com/latest/typescript |
Ok, I didn't understand that it was an i18n configuration. But still not working. My configuration :
const intervalPlural = require('i18next-intervalplural-postprocessor');
module.exports = {
i18n: {
defaultNS: 'translation',
serializeConfig: false,
fallbackLng: 'fr-FR',
locales: ['fr-FR', 'en-US', 'es-ES', 'de-DE', 'catchAll'],
defaultLocale: 'catchAll',
interpolation: {
escapeValue: false
},
react: {
transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p', 'u']
},
use: [intervalPlural],
allowObjectInHTMLChildren: true
}
}; Error :
EDIT : |
@pedrodurek can you help...? There is probably a bit of confusion. |
@azuken Ohh sorry, only
|
@pedrodurek Unfortunately, still not working ! It overrides React own definition types, so I've got an error like :
I've searched and tried to fix this, changing d.ts file : import React from 'react';
type ReactI18NextChild = React.ReactNode | Record<string, unknown>;
declare global {
namespace React {
interface HTMLAttributes<T> {
children?: ReactI18NextChild | Iterable<ReactI18NextChild>;
}
}
} Declare file into tsconfig.json (both include and typeRoots properties), changing file name but it continues to override base types. |
Hey @azuken, when you import react in the type declaration file it should import all original types as well. I created a project from scratch here and it worked https://github.com/pedrodurek/react-merge-type. |
Ok it's working if I move definition file into src folder, instead in root! Thank you for your help, is there any ticket, issue, MR opened to track when this will be implemented in this library ? |
Describe the bug
NextJS build is failing with React 18 and usage of component.
Occurs in next-i18next version
11.0.0
Steps to reproduce
Expected behaviour
No typing errors when using variables in Trans component
OS (please complete the following information)
The text was updated successfully, but these errors were encountered: