Reactjs react-I18下一个转换不适用于已传递的Prop元素

Reactjs react-I18下一个转换不适用于已传递的Prop元素,reactjs,typescript,i18next,react-i18next,Reactjs,Typescript,I18next,React I18next,我已经在我的项目中设置了一个i18转换器,虽然它对项目中的其他元素运行良好,但它似乎对传递的prop元素不起作用 这就是我使用i18的方式: import { useTranslation } from 'react-i18next'; const { t } = useTranslation(); //Using the translations {t('kitchenware')} // <-- Working fine {t(product?.name)} // <-- Er

我已经在我的项目中设置了一个i18转换器,虽然它对项目中的其他元素运行良好,但它似乎对传递的prop元素不起作用

这就是我使用i18的方式:

import { useTranslation } from 'react-i18next';
const { t } = useTranslation();

//Using the translations
{t('kitchenware')} // <-- Working fine
{t(product?.name)} // <-- Error here
name={t(product.name)} // <-- No error, but translations doesn't seem to work
从'react-i18next'导入{usetransation};
const{t}=useTranslation();
//使用翻译

{t('kitchenware')}/我错误地引用了i18脚本。在正确引用后,此操作有效。

这可能是因为如果TypeScript…product?.name as string可能有效?未获得此操作。抱歉。请尝试console.log(product.name)。。。。输出是正确的键吗?好的,我会试试。是的,这是正确的键,这会产生预期的正确输出。
src/pages/product/index.tsx:48:33
TS2769: No overload matches this call.
  Overload 1 of 2, '(key: string | TemplateStringsArray | (string | TemplateStringsArray)[], options?: string | TOptions<StringMap> | undefined): TFunctionResult', gave the following error.
    Argument of type 'string | undefined' is not assignable to parameter of type 'string | TemplateStringsArray | (string | TemplateStringsArray)[]'.
      Type 'undefined' is not assignable to type 'string | TemplateStringsArray | (string | TemplateStringsArray)[]'.
  Overload 2 of 2, '(key: string | TemplateStringsArray | (string | TemplateStringsArray)[], defaultValue?: string | undefined, options?: string | TOptions<StringMap> | undefined): TFunctionResult', gave the following error.
    Argument of type 'string | undefined' is not assignable to parameter of type 'string | TemplateStringsArray | (string | TemplateStringsArray)[]'.