i18next-fs-backend
i18next-fs-backend copied to clipboard
Create type definitions
🚀 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.
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.
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.
I just found these types: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/i18next-fs-backend Do they belong to this project? 🤔
looks like, but not created and not maintained by “us”
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'.
i18next-http-backend passes arrays and i18next-fs-backend passes strings
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
}
It would be nice to see template literal types being used like react-i18next
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