Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用变量相同键和值初始化Typescript对象时出现类型错误_Javascript_Reactjs_Typescript_Types - Fatal编程技术网

Javascript 使用变量相同键和值初始化Typescript对象时出现类型错误

Javascript 使用变量相同键和值初始化Typescript对象时出现类型错误,javascript,reactjs,typescript,types,Javascript,Reactjs,Typescript,Types,我有一个像这样的对象组件 const a = Text; // A component const b = Button; // A component const components = { a: a, b: b } 我使用ES6功能,并删除重复 const components = { a, b } 当我使用组件作为组件['a']时,我得到了某种类型的错误 由于类型的表达式,元素隐式具有“any”类型 “字符串”不能用于索引类型“

我有一个像这样的对象
组件

const a = Text;  // A component 
const b = Button; // A component
const components = {
   a: a,
   b: b
  }
我使用ES6功能,并删除重复

const components = {
       a,
       b
    }
当我使用组件作为
组件['a']
时,我得到了某种类型的错误

由于类型的表达式,元素隐式具有“any”类型 “字符串”不能用于索引类型“元素”


有趣。在这两种情况下,
组件的类型是什么?似乎都有效,您能提供示例代码进行复制吗?