元素隐式具有“任意”类型,因为类型“字符串”的表达式不能用于索引类型A

时间:2020-07-08 19:47:01

标签: javascript typescript

在本示例中,问题中的

类型ZStack{ Circle() .trim(from: 0.0, to: CGFloat(0.02702703)) .stroke(Color.red, lineWidth: 35) .frame(width: 330, height: 330) Text("2") .frame(width: 330 + 35, height: 300 + 35, alignment: .trailing) } .rotationEffect(Angle(degrees: -90)) 是指A类型 完全错误是

BadgeTypes

沙盒链接: https://codesandbox.io/s/typescript-type-checking-question-hkfmc (注意:但是由于某种原因,它没有显示错误-_-)

我在解决问题时遇到了问题。所有有关sorta的帖子都在我头上。将不胜感激,并伴随解释

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type A.No index signature with a parameter of type 'string' was found on type A

1 个答案:

答案 0 :(得分:2)

问题出在使用template stringbadge编制索引。

基本上:

// this is a string
let x = `${props.type}`;

// this is "success" | "secondary" | "alert" | "text"
let y = props.type;

如果您写props.theme.badge[props.type],类型检查器应该很高兴。