You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When defining a function with t as a parameter using the TFunction type, it should only include the specific namespaces needed within the function.
However, when attempting to use this function within a component that loads more other namespaces, TypeScript raises an error.
onst getNs3Text = (t: TFunction<["ns3"]>) => {
return t("ns3:third");
};
const Two = () => {
const { t } = useTranslation(["ns2", "ns3"]); // loaded two namespace
return (
<>
<div>{t("ns2:second")}</div>
<div>{getNs3Text(t)}</div> // ts-error 🛑 Type '"ns2"' is not assignable to type '"ns3"'.
</>
);
};
The function getNs3Text should compile successfully, considering that the function itself only requires the "ns3" namespace. The TypeScript error should not occur when using this function within a component that loads more other namespaces.
Allow for the inclusion of additional namespaces in the TFunction type when defining functions, ensuring compatibility with components that load multiple namespaces.
🐛 Bug Report
When defining a function with
t
as a parameter using theTFunction
type, it should only include the specific namespaces needed within the function.However, when attempting to use this function within a component that loads more other namespaces, TypeScript raises an error.
To Reproduce
codesandbox
Expected behavior
The function
getNs3Text
should compile successfully, considering that the function itself only requires the "ns3" namespace. The TypeScript error should not occur when using this function within a component that loads more other namespaces.Allow for the inclusion of additional namespaces in the TFunction type when defining functions, ensuring compatibility with components that load multiple namespaces.
Your Environment
The text was updated successfully, but these errors were encountered: