Skip to content
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

Conflicting types with i18next-fs-backend #103

Closed
2Pacalypse- opened this issue Nov 24, 2022 · 9 comments
Closed

Conflicting types with i18next-fs-backend #103

2Pacalypse- opened this issue Nov 24, 2022 · 9 comments
Assignees
Labels
typescript TypeScript

Comments

@2Pacalypse-
Copy link
Contributor

馃悰 Bug Report

Both this library and i18next-fs-backend library declare a (different) BackendOptions type for the backend property in the i18next module. See these two links:
https://github.com/i18next/i18next-http-backend/blob/master/index.d.ts#L125-L129
https://github.com/i18next/i18next-fs-backend/blob/master/index.d.ts#L50-L54

I don't know how you expected this to work, but the TypeScript compilation fails as soon as you have both of these libraries installed:

image

To Reproduce

Install both the i18next-http-backend and i18next-fs-backend libraries and run TypeScript.

Your Environment

  • i18next-http-version: 2.0.1
  • i18next-fs-version: 2.0.0
@adrai adrai added the typescript TypeScript label Nov 24, 2022
@adrai
Copy link
Member

adrai commented Dec 6, 2022

@pedrodurek Can you advice?

@adrai
Copy link
Member

adrai commented Dec 8, 2022

@2Pacalypse- are you using them together with i18next-chained-backend? => https://github.com/i18next/i18next-chained-backend#typescript

@2Pacalypse-
Copy link
Contributor Author

No, I use one on the frontend and one on the backend, so they're different configurations (but in the same project).

@adrai
Copy link
Member

adrai commented Dec 9, 2022

Have you also tried with skipLibCheck true ?

@adrai
Copy link
Member

adrai commented Dec 9, 2022

related: microsoft/TypeScript#33699

@2Pacalypse-
Copy link
Contributor Author

Have you also tried with skipLibCheck true ?

skipLibCheck ignores the errors in the declaration files so of course it doesn't show the errors then. However, that does nothing for actually fixing the problem and increasing the type safety.

It seems to me like the current system where each backend overwrites the CustomPluginOptions type simply can't work. Even the i18next-chained-backend does it, so I assume I'd see the same issue if I was using it.

related: microsoft/TypeScript#33699

That TypeScript issue might help, but I don't see it being implemented anytime soon, if ever.

My suggestion would be to simply export the BackendOptions type from each backend, and then allowing users to set it as a generic parameter or something to the init function. i18next-chained-backend should also probably use variadic generic types for its options, but that might be a bit more complicated to implement.

@adrai
Copy link
Member

adrai commented Dec 9, 2022

My suggestion would be to simply export the BackendOptions type from each backend, and then allowing users to set it as a generic parameter or something to the init function. i18next-chained-backend should also probably use variadic generic types for its options, but that might be a bit more complicated to implement.

sounds reasonable... what do you think @pedrodurek ? @2Pacalypse- would you like to start a PR?

@2Pacalypse-
Copy link
Contributor Author

I've made the PRs in the repos that I've been using and been able to test (other backends would probably need to be updated as well):
i18next/i18next#1878
#105
i18next/i18next-fs-backend#34

Note that I've only changed the parts that were relevant to my use case. I'm unfamiliar with the whole codebase so I'm not sure if anything else needs to be updated. The usage looks something like this:

image

Also, I'd like to point out that this is still a pretty bad solution to this problem, imo. I think a proper solution would be to change the API so each plugin/backend has its options defined at the same place they're initialized, instead of having a mix of all options in the init method. Something like this:

i18n
  .use(HttpBackend, /* http backend options */)
  .use(initReactI18next, /* react i18next options */)
  .init({
    // common i18next options
  })

@adrai
Copy link
Member

adrai commented Dec 10, 2022

i18next v22.2.0
i18next-http-backend v2.1.0
i18next-fs-backend v2.1.0

@adrai adrai closed this as completed Dec 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants