react-i18next: Return type problem

🐛 Bug Report

Upon updating to v12.0.0 return type issue appears as follows: image

As you can see, explicitly defining the return type to string | undefined shows an error. But defining the type as string alone doesn’t show any error.

Compare that with explicitly defining the value as below, the behavior sounds weird to me.

image

As you can see here, if the type is string or string | undefined and the value is null, the error appears (expected).

Expected behavior

string | undefined return type should work without issues as it was before updating to v12.0.0.

Your Environment

  • runtime version: node v16
  • i18next version: v12.0.0
  • os: Mac

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (6 by maintainers)

Most upvoted comments

Hey @eiskalteschatten,

I had the same issue and what worked for me was putting the override in my i18n.ts file like so:

import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';

declare module 'i18next' {
  interface CustomTypeOptions {
    returnNull: false;
  }
}

i18n
  .use(initReactI18next)
  .init({
    returnNull: false,
  });

export default i18n;

Why is this ticket closed, it’s still an issue?

@millar,

Thank you for that example. Worked for me as well. The thing that bothers me now is I don’t know why that worked! Can anyone explain why that putting the override in the i18n.ts file fixed the issue when adding a i18next.d.ts file with the same content didn’t?

Hey @millar,

Thanks for the example. That worked wonderfully for me!