-
-
Notifications
You must be signed in to change notification settings - Fork 673
Improve t function return type #1175
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
Conversation
return value of |
No problem for me. It's good improvement, thanks. |
@jamuhl This can be a patch release. Not urgent, can be included in any next batch release. |
This turned out to have been surprisingly breaking. I'm just not sure if it's a good or a bad break. Every single use of I wonder if there is a way to declare, somewhere, what kind of result a specific key should have. Because of how typescript generic arguments work, the TResult is very inconvenient to declare (you're forced to pass the key name twice and then the type of TValue). Finding a way to that could make TValue itself safer. This could be made non-breaking by changing the default to be the same as the old value. It's still not perfect, though. Looking at how the old type was inferred it seems to actually prefer a contextual type if one is available, only ever falling back to Getting types right for i18next will probably require adding generics in a bunch of other places, including the interfaces and the components from |
Why these arguments are "hidden anys" (well, "hidden whatever the type of the Let's take this t<
TKeys extends string = string,
TValues extends object = object,
TResult extends string | object | Array<string | object> =
| string
| object
| Array<string | object>
>(
key: TKeys | TKeys[],
options?: TranslationOptions<TValues>
): TResult The type of Having a The same goes for Also, because these generics are in the function itself instead of passed through a chain derived all the way from the This is actually something that is caught by a custom tslint rule they have running in Is this an argument for moving types to DT? An argument for DT to make their rules more widely available? Who knows, they might port them over to eslint given how it's in their roadmap now. Contrast this with the way To clarify, the |
See the master where the ts usage tests are broken apart. @tkow generates TKeys for usage. This is probably better filed as an open issue with tagged participants. Commenting on a merged PR is not bound to result in a response or change. |
BTW @Jessidhia I think I have encountered some of what you are experiencing while refactoring and understand the cause one of your issues - a mismatch between TranslateFunction and WithT. I'm working on it here #1180 |
I'd like to have a more specific type for t function.
Am I wrong or it's always a "string" ?