Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6212

How do I find element in object typescript code

$
0
0

So, am trying to assign colours to my icons dynamically ... but this line of code keeps complaining,

let icon = iconsList[name];

When I hover of it .. This is the explanation "

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ heart: string; star: string; like: string; dislike: string; flash: string; marker: string; filter: string; user: string; circle: string; hashtag: string; calendar: string; chevronLeft: string; optionsV: string; optionsH: string; chat: string; explore: string; }'. No index signature with a parameter of type 'string' was found on type '{ heart: string; star: string; like: string; dislike: string; flash: string; marker: string; filter: string; user: string; circle: string; hashtag: string; calendar: string; chevronLeft: string; optionsV: string; optionsH: string; chat: string; explore: string; }'.ts(7053)

interface Props{    name:string,}const Icon = ({ name }:Props) => {    const iconsList = {      heart: '',      star: '',      like: '',      dislike: '',      flash: '',      marker: '',      filter: '',      user: '',      circle: '',      hashtag: '',      calendar: '',      chevronLeft: '',      optionsV: '',      optionsH: '',      chat: '',      explore: ''    };    let icon = iconsList[name];    icon = icon.substr(3);    icon = String.fromCharCode(parseInt(icon, 16));    return icon;  };  export default Icon;

ScreenShot of the code in Vscode On line 25, am trying to pick the specific icon color but it complains


Viewing all articles
Browse latest Browse all 6212

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>