【发布时间】:2021-10-16 11:53:11
【问题描述】:
我在Typescript中有这个代码:
const [history, setHistory] = useState([Array(9).fill(null)]);
const newHistory = history.slice(0, currentStep + 1);
当我想使用这样的扩展运算符设置新状态时:
setHistory(...newHistory);
我有错误:
展开参数必须要么具有元组类型,要么被传递给休息参数。
有人可以帮助我吗,我怎样才能正确输入这个?
【问题讨论】:
标签: reactjs typescript spread