Closed stevensacks closed 3 months ago
Could you check if it's fixed in 6.2.1?
Hi @sergiodxa,
Same error here with 6.2.1 (only with the getFixedT
method, the useTranslation
method is working as before):
I can "solve" the problem by defining the namespace as the second argument to the t
function (but this is not the intended use):
N.B. I have the same typing definition as @stevensacks:
import { type resources, type defaultNS } from '~/app/locales/i18n.ts';
declare module 'i18next' {
interface CustomTypeOptions {
defaultNS: typeof defaultNS;
resources: typeof resources.fr;
}
}
And translations that do not have dynamic parameters also have an error:
I added typed namespaces to the getFixedT tests and confirmed that now it should work in v6.3.0
I confirm that is working well, thanks a lot for reactivity!
Describe the bug
Something in remix-i18next 6.2.0 broke something with typescript typed language files and now keys in the
t
function returned byi18next.getFixedT()
throw TS errors if you don't includekeyPrefix
in thegetFixedT()
options. It's still working at runtime, the keys are returning their values. But, TypeScript complains inside thet()
function. Adding thekeyPrefix
option makes the TS error go away.TS Error
With KeyPrefix
There is also a TS error if you do not include the namespace(s) param to
getFixedT()
and instead pass thens
as an option int()
, where thekeyPrefix
option is not available. I have not figured out a way to resolve this one. Again, the string values are still returned correctly at runtime, but TypeScript has an error.Your Example Website or App
https://stackblitz.com/edit/remix-run-remix-qazht2
Steps to Reproduce the Bug or Issue
Stackblitz unfortunately appears to not read in
*.d.ts
files in the project, so you cannot reproduce this issue in stackblitz because it doesn't apply any typing to i18next keys at all. Everything else in the project is set up in Stackblitz.Adding typing is as simple as adding a type definition file
i18next.d.ts
to your project, as per their documentation.This works as expected outside of Stackblitz. I couldn't figure out how to get it to work in Stackblitz. If you know how, you should be able to turn that on and reproduce the issue.
Expected behavior
Prior to 6.2, the types were correctly identifying the namespaces and key paths. Now, they're broken as described above.
Screenshots or Videos
No response
Platform
Additional context
Rolling back to remix-i18next v6.1.1 fixes the issue.