Reputation: 251
I am using Typescript in my React-native project.Code working properly as per desired output.but getting typescript conflicts.
Sharing my code snippets
Importing json object from other config files.
import api from 'config/api.json'
languageSet = async (value: string) => {
setStorageItem('language', value)
this.setState({ setLoading: true })
const language = await getStorageItem('language');
if (language) {
const baseURL = api[language][environment] ? api[language][environment].api : api[language].qa.api;
}
else {
const baseURL = api.ch[environment] ? api.ch[environment].api : api.ch.qa.api;
}
}
I want to make dynamic baseURl that's why using language const to set it's value.
Following error I am facing.
Upvotes: 1
Views: 153
Reputation: 7985
you need to put type on the getStorageItem
function
try this way
const language = await getStorageItem('language') as 'ch';
if you have some language you can do
const language = await getStorageItem('language') as 'ch' | 'other_language';
Upvotes: 1