编程语言的子类型,分为两种:

名义子类型 Java和C#中就是名义子类型,必须显示继承,用来extends才是子类型

结构子类型 只要结构相同,就是子类型

typescript是结构子类型。

type Foo = {
    age: number
}

type Bar = {
    age: number
}

是一样的类型,不需要extends。

type Foo = {
    name: string,
    age: number
}

type Bar = {
    name: string
}

Foo是Bar的子类型。

相关文章:

  • 2021-08-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2022-01-06
  • 2021-04-09
猜你喜欢
  • 2021-07-15
  • 2022-12-23
  • 2022-12-23
  • 2021-07-29
  • 2021-07-17
  • 2021-12-11
  • 2021-11-15
相关资源
相似解决方案