i18next / i18next-http-backend

i18next-http-backend is a backend layer for i18next using in Node.js, in the browser and for Deno.
MIT License
450 stars 69 forks source link

Typescript definition is incorrect and resulting in a compilation failure #69

Closed bert-bae closed 3 years ago

bert-bae commented 3 years ago

🐛 Bug Report

Running tsc on the 1.2.5 and 1.2.6 versions to compile typescript results in the following error:

Class 'I18NextHttpBackend' incorrectly implements interface 'BackendModule<BackendOptions>'.
  Property 'create' is optional in type 'I18NextHttpBackend' but required in type 'BackendModule<BackendOptions>'.

There is no compilation issue for versions 1.0.x

Expected behavior

Typescript is able to compile.

Your Environment

adrai commented 3 years ago

Does this also happen with the newest i18next version?

adrai commented 3 years ago

//cc: @pedrodurek

pedrodurek commented 3 years ago

That's odd, the property is optional in both dependencies, could you provide an example in Codesandbox or similar?

bert-bae commented 3 years ago

It looks like updating i18next to the latest works and has the correct type definitions in i18next BackendModule for it to compile correctly with i18next-http-backend 1.2.x.

Issue was i18next type definition for 19.4.4

export interface BackendModule<TOptions = object> extends Module {
  type: 'backend';
  init(services: Services, backendOptions: TOptions, i18nextOptions: InitOptions): void;
  read(language: string, namespace: string, callback: ReadCallback): void;
  /** Save the missing translation */
  create(languages: string[], namespace: string, key: string, fallbackValue: string): void; <<< Not optional
  /** Load multiple languages and namespaces. For backends supporting multiple resources loading */
  readMulti?(languages: string[], namespaces: string[], callback: MultiReadCallback): void;
  /** Store the translation. For backends acting as cache layer */
  save?(language: string, namespace: string, data: ResourceLanguage): void;
}

Fix: