首页 > 解决方案 > “DetailedHTMLProps”类型上不存在属性“索引”, HTMLLI元素>

问题描述

我正在使用 react-typescript 但在我的列表中index但它会引发警告:


interface  PropsSortableElement {
  children: any;
  index: any;
  zIndex?: number;
}


export const SortableItem = SortableElement(({ children, index, zIndex }: PropsSortableElement) => {
  const classes = useStyles();

  return (
    <li className={classes.sortableItem} index={index} style={{ zIndex: zIndex || 1 }}>
      {children}
    </li>
  );
});

所以我收到一个警告index


TS2322: Type '{ children: any; className: string; index: any; style: { zIndex: number; }; }' is not assignable to type 'DetailedHTMLProps<LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>'.   Property 'index' does not exist on type 'DetailedHTMLProps<LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>'.

怎么能解决?

标签: reactjstypescript

解决方案


推荐阅读