简体   繁体   English

React typescript 错误:元素隐式具有“任何”类型

[英]React typescript error: Element implicitly has an 'any' type

I am a beginner at typescript and I am using it in reactjs but I am getting errors.我是 typescript 的初学者,我在 reactjs 中使用它,但我遇到了错误。 Could someone please help me with how to resolve this issue?有人可以帮我解决这个问题吗? Element implicitly has an 'any' type because expression of type 'string' can't be used to index type . Element implicitly has an 'any' type because expression of type 'string' can't be used to index type

export const colors = {
  RootBackground: "#fff",
}



style = {
  [
    buttonStyle ? buttonStyle : styles.button,
    {
      backgroundColor: colors[color],
      width
    },
  ]
}

Note: Error is on this line colors[color]注意:错误是在这条线上colors[color]

Limit color to be a key of colors:限制color为 colors 的键:

interface Props {
  color: keyof typeof colors
  // other props
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeScript:元素隐含地具有 RegExp 的“任何”类型 - TypeScript: Element implicitly has an 'any' type for RegExp 元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型 React Typescript - Element implicitly has an 'any' type because expression of type 'string' can't be used to index type React Typescript 打字稿:可能导致此错误的原因是什么? “元素隐式具有'任意'类型,因为类型'对象'没有索引签名” - Typescript: what could be causing this error? “Element implicitly has an 'any' type because type 'Object' has no index signature” 键入一个对象的问题反应typescript - Element隐式有一个'any'类型因为type' - issue typing an object react typescript - Element implicitly has an 'any' type because type' TypeScript 元素隐含一个“任何” - TypeScript Element implicitly has an 'any' Typescript错误,如何解决此问题:元素隐式具有“ any”类型,因为type - Typescript error, how to correct this: Element implicitly has an 'any' type because type 如何访问typescript中的Enum? 给出错误“元素隐式具有任何类型,因为索引表达式不是数字类型” - How to access Enum in typescript ? giving error "Element implicitly has an any type because index expression is not of type number" 映射打字稿参数:绑定元素“列”隐式具有“任何”类型 - Map typescript parameter: Binding element 'columns' implicitly has an 'any' type 成员“xyz”隐含地具有“任何”类型。 使用 react 和 typescript 时出错 - Member 'xyz' implicitly has an 'any' type. Error using react and typescript TypeScript 错误参数“props”隐式具有“any”类型 - TypeScript error Parameter 'props' implicitly has an 'any' type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM