[英]Element implicitly has an 'any' type because expression of type 'string' can't be used to index type in React Typescript
I am using Typescript in my React-native project.Code working properly as per desired output.but getting typescript conflicts.我在我的 React-native 项目中使用 Typescript。代码按照需要正常工作 output。但是得到 Z1E35BCBD085DBA1089CCFBD7085DBA 冲突。54
Sharing my code snippets分享我的代码片段
Importing json object from other config files.从其他配置文件导入 json object。
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.我想制作动态 baseURl,这就是为什么使用语言 const 来设置它的值。
Following error I am facing.我面临以下错误。
you need to put type on the getStorageItem
function您需要在
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';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.