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
453 stars 70 forks source link

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

Closed jonkoops closed 2 years ago

jonkoops commented 2 years ago

🐛 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.

adrai commented 2 years ago

can you try with i18next v22.0.6 ?

jonkoops commented 2 years ago

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)
   }
}
adrai commented 2 years ago

no, it was a string since the beginning: https://github.com/i18next/i18next-http-backend/commit/767e0b6d4946477450a3f0c07bd79812a2490cdd#diff-92bbac9a308cd5fcf9db165841f2d90ce981baddcb2b1e26cfff170929af3bd1R65

jonkoops commented 2 years ago

Then it's much more correct :+1: