i18next / i18next-http-backend

i18next-http-backend is a backend layer for i18next using in Node.js, in the browser and for Deno.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`CallbackError` is incorrectly set as a `string` value

jonkoops opened this issue Β· comments

πŸ› Bug Report

The value passed for CallbackError is incorrect. According to the type definition it can only be of type Error | null | undefined, but in the code it's also being passed as a string in multiple occasions.

Expected behavior

In the aforementioned cases the value should be passed as the type Error.

can you try with i18next v22.0.6 ?

Yeah, that works. But should the fix not be that it is always an instance of Error? Also this is a breaking change to the types as folks might not be checking for string values at this time.

For example:

const callback: MultiReadCallback = (err, data) => {
   if (err) {
     // This will now be a TypeScript error, as 'message' does not exist on type 'string'
     console.log(err.message)
   }
}

Then it's much more correct πŸ‘