i18next-fs-backend icon indicating copy to clipboard operation
i18next-fs-backend copied to clipboard

Create type definitions

Open pedrodurek opened this issue 4 years ago • 8 comments
trafficstars

🚀 Feature Proposal

For now, there are no type definitions for i18next-fs-backend. This issue is just for reference, I'm going to work on it as soon as I can.

pedrodurek avatar Mar 21 '21 20:03 pedrodurek

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Mar 28 '21 22:03 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 05 '21 06:04 stale[bot]

I just found these types: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/i18next-fs-backend Do they belong to this project? 🤔

mad-it avatar Apr 29 '21 11:04 mad-it

looks like, but not created and not maintained by “us”

adrai avatar Apr 29 '21 13:04 adrai

Since the latest release of i18next-http-backend (since 1.2.0) I also get the below Typescript error when setting the loadPath option and using i18next-http-backend and i18next-fs-backend in the same app. I double-checked the parameters of my custom loadPath handler and the parameters are not arrays but just a string for lng and ns. I tried it with and without the DefinitlyTyped types.

No overload matches this call.
  Overload 1 of 2, '(callback?: Callback | undefined): Promise<TFunction>', gave the following error.
    Argument of type '{ backend: { loadPath: (lng: string, ns: string) => string; }; }' is not assignable to parameter of type 'Callback'.
      Object literal may only specify known properties, and 'backend' does not exist in type 'Callback'.
  Overload 2 of 2, '(options: InitOptions, callback?: Callback | undefined): Promise<TFunction>', gave the following error.
    Type '(lng: string, ns: string) => string' is not assignable to type 'LoadPathOption | undefined'.

medihack avatar May 06 '21 00:05 medihack

i18next-http-backend passes arrays and i18next-fs-backend passes strings

adrai avatar May 06 '21 07:05 adrai

Yes, I know. But unfortunately, Typescript doesn't seem to know, or better to say, mistakes types.

import i18n from "i18next"
import Backend from "i18next-fs-backend"
...
const createClient = () => {
  const instance = i18n.createInstance()

  // here is where the TS error appears
  const initPromise = instance.use(Backend).init({ backend: { loadPath } })
  return { i18n: instance, initPromise }
}

function loadPath(lng: string, ns: string) {
  ...
  return path
}

medihack avatar May 06 '21 09:05 medihack

It would be nice to see template literal types being used like react-i18next

daniellwdb avatar Feb 15 '22 09:02 daniellwdb

v1.2.0 should now include the types directly for i18next < v22.0.0 and v2.0.0 should now include the types directly for i18next >= v22.0.0

adrai avatar Oct 26 '22 08:10 adrai