diff --git a/README.md b/README.md index 40f91c9..5d818e7 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,25 @@ const HttpApi = new HttpApi(); HttpApi.init(null, options); ``` +## TypeScript + +To properly type the backend options, you can import the `HttpBackendOptions` interface and use it as a generic type parameter to the i18next's `init` method, e.g.: + +```ts +import i18n from 'i18next' +import HttpBackend, { HttpBackendOptions } from 'i18next-http-backend' + +i18n + .use(HttpBackend) + .init({ + backend: { + // http backend options + }, + + // other i18next options + }) +``` + ---

Gold Sponsors

diff --git a/index.d.ts b/index.d.ts index 35cf376..e5b8657 100644 --- a/index.d.ts +++ b/index.d.ts @@ -9,7 +9,7 @@ type AddPathOption = | string | ((lng: string, namespace: string) => string) -interface BackendOptions { +export interface HttpBackendOptions { /** * path where resources get loaded from, or a function * returning a path: @@ -59,7 +59,7 @@ interface BackendOptions { * can be used to support XDomainRequest in IE 8 and 9 */ request?( - options: BackendOptions, + options: HttpBackendOptions, url: string, payload: {} | string, callback: RequestCallback @@ -95,11 +95,11 @@ interface RequestResponse { } export default class I18NextHttpBackend - implements BackendModule + implements BackendModule { static type: "backend"; - constructor(services?: any, options?: BackendOptions); - init(services?: any, options?: BackendOptions): void; + constructor(services?: any, options?: HttpBackendOptions); + init(services?: any, options?: HttpBackendOptions): void; readMulti?( languages: string[], namespaces: string[], @@ -120,11 +120,5 @@ export default class I18NextHttpBackend ): void; type: "backend"; services: any; - options: BackendOptions; -} - -declare module "i18next" { - interface CustomPluginOptions { - backend?: BackendOptions; - } + options: HttpBackendOptions; }