i18n-js Property 't' does not exist on type 'typeof import'

2k Views Asked by At

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:

enter image description here

How can i solve that?

1

There are 1 best solutions below

1
On

You can use const i18n = require('i18n-js'); and you'll be fine.