We have decided to implement multilanguage support in our app and encountered an issue with function execution.
const someFunction = (lang: string, url: string) => any
If we mistakenly execute the function like this:
someFunction('/some/url', 'pl')
Instead of
someFunction('pl', '/some/url')
This can cause problems as TypeScript does not show any errors since both parameters are strings.
To address this, we changed the function declaration to use an enum for language:
enum Language {
PL,
ENG,
ES
}
const someFunction = (lang: Language, url: string) => any
Now the function can be executed correctly like this:
someFunction(Language.PL, '/some/url')
Despite resolving this issue, we encountered a complication with i18next.
The WithTranslation interface specifies the language property as a string:
i18n: {
language: string
}
Similarly, the useTranslation hook returns the same i18n object with the language as a string.
I have tried various approaches but my TypeScript skills are limited, and I am unsure how to change the i18n property to use the Language enum instead of a regular string.
If anyone has a solution to this problem, I am willing to make a donation to charity as a token of appreciation. Thank you!