遍历列表索引错误

时间:2021-07-28 16:23:24

标签: python loops if-statement

我正在尝试遍历一个列表,如果 list[index] == previous list[index] so == list[index-1],脚本应该删除这两个元素。

但是我收到了一个奇怪的索引错误,我认为这不应该发生:

这是我的代码

const removeType = <T extends { type: unknown }>({ type, ...rest }: T) => rest;

但它因以下错误而崩溃

const x = removeType({ type: 1, somethingElse: "hello" })

console.log(x.somethingElse);
// console.log(x.type) // error!

预先感谢您帮助我。

0 个答案:

没有答案
相关问题