1. // 类与接口
    2. export = {}
    3. // 建议一个接口只实现一个约束
    4. // interface EatAndRun {
    5. // eat (food: string): void
    6. // run (distance: number): void
    7. // }
    8. interface Eat {
    9. eat (food: string): void
    10. }
    11. interface Run {
    12. run (distance: number): void
    13. }
    14. // 实现了接口,就一定要有接口的内容
    15. class Person implements Eat, Run {
    16. eat (food: string): void {
    17. console.log(`优雅的进餐:${food}`)
    18. }
    19. run (distance: number) {
    20. console.log(`直立行走:${distance}`)
    21. }
    22. }
    23. class Animal implements Eat, Run {
    24. eat (food: string): void {
    25. console.log(`呼噜呼噜的吃:${food}`)
    26. }
    27. run (distance: number) {
    28. console.log(`爬行:${distance}`)
    29. }
    30. }