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.

20 lines
414 B

2 years ago
  1. // 交叉类型:功能类似 extends,用于组合多个类型为一个类型(常用于对象类型)
  2. interface Person {
  3. name: string
  4. say(): number
  5. }
  6. interface Contact {
  7. phone: string
  8. }
  9. // PersonDetail 同时具有 Person 和 Contact 的属性和方法
  10. type PersonDetail = Person & Contact
  11. let obj: PersonDetail = {
  12. name: 'jack',
  13. phone: '123456',
  14. say() {
  15. return 1
  16. }
  17. }