如何在for循环中使用打字稿类型

时间:2020-05-12 05:05:44

标签: reactjs typescript

我有类型

  interface Test {
  Id?: string
  Activity?: string
}

interface Previous {
  Id?: string
  Name?: string
  Original: Test
}

interface MainProduct {
  Id?: string
  Name?: string
  Original?: Previous
}

    type Product =  MainProduct | Previous

    for (let activity in groupedProductsByActivity as Array<Product>) {


    }

但这给了我一个编译时错误。谁能帮我如何将这种类型添加到for循环数据中?

谢谢。

错误是

Conversion of type 'Dictionary<(Previous | VIPClusterAssortmentProduct)[]>' to type '(Previous | MainProduct)[]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first

0 个答案:

没有答案