I installed the i18n-js library in a react-native project, and I got a problem with typescript.
I use the library this way:
i18n.js
import i18n from 'i18n-js';
import en from './locales/en.json';
import es from './locales/es.json';
i18n.defaultLocale = 'en';
i18n.locale = 'en';
i18n.fallbacks = true;
i18n.translations = {en, es};
export default i18n;
Auth.tsx
import i18n from '../../i18n';
...
Alert.alert(i18n.t('login.accountCreatedTitle'));
I got this annoying Typescript error:
How can i solve that?
You can use
const i18n = require('i18n-js');
and you'll be fine.