-
-
Notifications
You must be signed in to change notification settings - Fork 641
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
Allow unknown keys, when a defaultValue
is provided
#1867
Comments
Would you like to send a Pull Request to address this? Remember to add unit tests. |
I'll put it on my todo list. It's long. 😉 |
So I had some time and adding the overloads was actually pretty straight forward. here they are: <
TDefaultResult extends DefaultTFuncReturn = string,
TInterpolationMap extends object = StringMap,
>(
key: string | string[],
options: TOptions<TInterpolationMap> & { defaultValue: string },
): TFuncReturn<N, string, TDefaultResult, TKPrefix>;
<
TDefaultResult extends DefaultTFuncReturn = string,
TInterpolationMap extends object = StringMap,
>(
key: string | string[],
defaultValue: string,
options?: TOptions<TInterpolationMap> | string,
): TFuncReturn<N, string, TDefaultResult, TKPrefix>; I tested them and they work as expected. I might have to add a few more since the return value is different, when I could create a pr, but since this is a types-only change, I failed to find the appropriate testing suite (was looking for tsd). Can you point me in the right direction? |
A quick check of those didn't help. In The file So I'm guessing this might be a configuration issue? Pls advise. |
Hey @janpaepke, sorry for the delayed response. Actually, I'm trying to get rid of the some function overloads due to some limitations and to speed up the compilation time. I'll support what you want, just give me a few more days. |
Ok sure! Let me know if I can help in any way! Also: no need to apologise 😊. |
@janpaepke try v22.4.5 in the meantime... it might be some performance changes will need to be done but in the meantime I added also some other t function overloads.... |
works as expected. I guess this concludes this issue? Should we close it? |
💥 Regression Report
This isn't really a functional regression, more like a convenience regression, it only concerns the new Typescript enhancements.
When using the t function it is now impossible to use with keys that don't exist in the default namespace, even when a default value is provided, which it could fall back to.
This forces me to always add every key to my default namespace's resource file.
Usually in our workflow we only add translations inline using the defaultValue, when developing a new feature.
This is because things often change.
Only once something is production ready, we run i18next-parser to extract all keys and add translations.
Proposal
I propose to add additional overloads for when a default value is provided (one for
t('key', 'defaultValue')
, one fort('key', { defaultValue: 'value' })
, where the key can be any string.Last working version
Worked up to version: 21
Stopped working in version: 22
To Reproduce
Steps to reproduce the behavior:
Your Environment
The text was updated successfully, but these errors were encountered: