-
-
Notifications
You must be signed in to change notification settings - Fork 588
Do not union any
in Translation
#1534
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
Comments
Interesting. Did you try to run the lint job? |
That's referenced in my second point:
The restriction can be circumvented by writing If you remove that comment, the linting fails. |
I also kindly ask for this improvement. |
I'm on it :) |
A little update. I've started pocking around to implement this fix and could already do the following PR I was ready to remove the When I'm using To simplify it, I'd say that the Could I make the required changes, or @CodeAndWeb do you see something getting against it ? Cheers |
I've made some more modifications and completely removed "any" from the interface now. The issue why the "any" was required was the tests. Adding the "as string" fixed the issue. I think it came from
|
@CodeAndWeb Be careful, this is not only the test, but also when we're using it in our own project. It isn't able to detect the type because the type can really have different types (string, Translate[], ...). Se we would need to add the myTranslation?: string
constructor() {
this.myTranslation = this.translateService.instant('TEST') as string
} Which IMO isn't a good option... This is the reason why I asked about the if the |
@rbalet That's already the case. Our code has quite a few calls like Why do you state that writing |
@Ghostbird what I ment with that is
2 or 3 will let us then remove the As I assume most people are only caring of the What do you think of it? |
From a technical standpoint, I completely agree with you. I don't like the API for get() and instant() either - but I currently see no way to change it because it might make many users unhappy.
{
"languages":
{
"DE": "German",
"EN": "English",
"FR": "French",
}
} and feed this e.g. into a language picker.
Currently you can still write this:
Setting the result to
That would allow writing The result is at least |
What I would prefer is a way to configure the library like this - but this obviously can't exist in typescript:
|
@CodeAndWeb now that I think about it. It's could actually be doable with type generic. But I'll make a proposition in that direction :) |
Uh oh!
There was an error while loading. Please reload this page.
According to the lines below, the
any
union is necessary.core/projects/ngx-translate/src/lib/translate.service.ts
Lines 19 to 26 in ee77f16
However, this causes me issues, since the type of
Translation
isany
becauseany
overrides everything.So I tried this in my local repo (
"typescript": "^5.4.5"
) and I get no such recursion message.I can think of two possible causes (but there might be another reason):
TranslationObject
an interface. However the| any
was not removed by accident.Can this
| any
be removed?The text was updated successfully, but these errors were encountered: