You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
405 B

2 years ago
  1. // 两个类的兼容性演示:
  2. class Point {
  3. x: number
  4. y: number
  5. }
  6. class Point2D {
  7. x: number
  8. y: number
  9. }
  10. const p: Point = new Point2D()
  11. class Point3D {
  12. x: number
  13. y: number
  14. z: number
  15. }
  16. // 对象成员多的可以赋值给对象成员少的,Point3D 的成员多过 Point,所以可以赋值。
  17. const p1: Point = new Point3D()
  18. // 对象成员少的不能给对象多的