[英]Property 'index' does not exist on type '{}'
if (this.props.children) {
return React.Children.map(this.props.children, (child, i) => {
if (React.isValidElement(child)) {
return React.cloneElement(child as React.ReactElement<any>, {
index: child.props.index || i // <-- line that causes error
});
}
return child;
});
}
Gives compile error error TS2339: Property 'index' does not exist on type '{}'.
给出编译错误
error TS2339: Property 'index' does not exist on type '{}'.
Why?为什么? How to fix?
怎么修?
Try this,尝试这个,
child.props['index']
Note: In typescript
you can not access indexed properties using the dot notation.注意:在
typescript
您不能使用点表示法访问索引属性。 So it will give compile time error所以它会给出编译时错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.