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
Allow Dynamic Namespace Inclusion in TFunction for TypeScript Compatibility #1699
Comments
If you know how to accomplish this feel free to provide a PR. import { useTranslation } from "react-i18next";
import { getNs3Text } from "../utils/getNs3Text";
const Two = () => {
const { t: t2 } = useTranslation("ns2");
const { t: t3 } = useTranslation("ns3");
return (
<>
<div>{t2("second")}</div>
<div>{getNs3Text(t3)}</div>
</>
);
};
export default Two; |
I look into the code, and the issue seems to be related to /** ************************
* T function declaration *
************************* */
export interface TFunction<Ns extends Namespace = DefaultNamespace, KPrefix = undefined> {
$TFunctionBrand: $IsResourcesDefined extends true ? `${$FirstNamespace<Ns>}` : never;
<
const Key extends ParseKeys<Ns, TOpt, KPrefix> | TemplateStringsArray,
const TOpt extends TOptions,
Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, KPrefix>, TOpt>,
const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>,
>(
...args:
| [key: Key | Key[], options?: ActualOptions]
| [key: string | string[], options: TOpt & $Dictionary & { defaultValue: string }]
| [key: string | string[], defaultValue: string, options?: TOpt & $Dictionary]
): TFunctionReturnOptionalDetails<Ret, TOpt>;
} What is the purpose of |
//cc @jtbandes |
Also see prior discussion on this |
馃悰 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: