【问题标题】:How to inherit all properties of a type into another type and some more如何将一种类型的所有属性继承到另一种类型等等
【发布时间】:2021-06-13 22:50:04
【问题描述】:

我有两种类型,一种继承了其他的所有属性,所以我将它们全部重写在孩子身上。有写这个的捷径吗?

type Parent = {
  a: string,
  b: string
}

type Child = {
  a: string,
  b: string,
  c: number
}

【问题讨论】:

标签: typescript


【解决方案1】:

基于Possible to extend types in Typescript?

你可以这样做:

type Parent = {
  a: string,
  b: string
}

type Child = Parent & { c: number }

【讨论】:

    猜你喜欢
    • 2011-05-04
    • 1970-01-01
    • 1970-01-01
    • 2021-04-11
    • 2010-09-19
    • 1970-01-01
    • 2011-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多