小编Hit*_*mar的帖子

类型“number”不可分配给类型“string”。ts(2322)

这是我的代码片段

      {animals.map((animal: Array<any>, i: number) => {
        return <span  id={i} className={index === i ? "animal active" : "animal"} onClick={handleAnimalSelect}></span>;
      })}

Run Code Online (Sandbox Code Playgroud)

错误

(JSX attribute) React.HTMLAttributes<HTMLSpanElement>.id?: string
Type 'number' is not assignable to type 'string'.ts(2322)
index.d.ts(1760, 9): The expected type comes from property 'id' which is declared here on type 'DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>'
Run Code Online (Sandbox Code Playgroud)

html arrays typescript reactjs

0
推荐指数
1
解决办法
4765
查看次数

标签 统计

arrays ×1

html ×1

reactjs ×1

typescript ×1