【问题标题】:how to nest an array of type alias in a type alias in typescript?如何在打字稿的类型别名中嵌套类型别名数组?
【发布时间】:2020-10-20 21:42:28
【问题描述】:
type subProp = {
  id: string,
  name: string
};

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

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

【问题讨论】:

    标签: typescript typescript-typings typescript-types


    【解决方案1】:

    您可以将items 声明为subPropsarraysubscriptions 作为具有iditems 类型的数组:

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

    【讨论】:

    猜你喜欢
    • 2017-03-09
    • 1970-01-01
    • 2017-06-12
    • 1970-01-01
    • 2013-10-14
    • 1970-01-01
    • 2020-08-18
    • 2019-11-02
    • 1970-01-01
    相关资源
    最近更新 更多