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.

17 lines
391 B

2 years ago
  1. // 接口
  2. interface Singable {
  3. sing(): void
  4. name: string
  5. }
  6. // 使用 implements 关键字让 class 实现接口
  7. // Person 类实现接口 Singable , 意思是 Person 类中必须提供 Singable 接口中指定的所有方法和属性
  8. class Person implements Singable {
  9. name = 'jack'
  10. sing() {
  11. console.log('666666')
  12. }
  13. }
  14. const p = new Person()
  15. console.log(p.name)