如何在打字稿的类型别名中嵌套类型别名数组?

how to nest an array of type alias in a type alias in typescript?

type subProp = {
  id: string,
  name: string
};

type ParentProps = {
  subscriptions?: [
    {
      id: string,
      items: [???Array Of subProp???]
    }
  ]
}

这种情况在只有类型别名的打字稿中可行吗?如果可以,该怎么做?我在网上找不到任何可行的选择。如果不是,还有什么选择?

您可以将 items 声明为 subPropsarray,将 subscriptions 声明为 iditems 类型的数组:

type subProp = {
  id: string,
  name: string
};

type ParentProps = {
    subscriptions?: {
        id: string,
        items: subProp[];
    }[];  
}