接口扩展:接口可以继承接口
interface Animal{ eat():void;}interface Person extends Animal{//接口的继承 work():void;}class Programmer{ public name:string; public age?:number;//可选参数 constructor(name:string,age?:number){//age是可选参数 this.name=name; this.age=age; } coding(code:string){ console.log(this.name+code) }}class Web extends Programmer implements Person{ //web继承program复制代码
实现Person接口
constructor(name:string){ super(name) } eat(){//必须实现Person继承Animal的eat方法 console.log(this.name+'喜欢吃馒头') } work(){//必须实现Person的eat方法 console.log(this.name+'写代码'); }}var w=new Web('小李');w.eat();w.coding('写ts代码');复制代码感谢: 参考学习:https://www.itying.com: 自己总结到有道云笔记里面有更加清楚的标注方便查阅: * Typescript 介绍 http://note.youdao.com/noteshare?id=c3e0d5810580041ade028a345519ce96&sub=E882CE350AC94C5596B146908C406274 * typeScript中的数据类型 http://note.youdao.com/noteshare?id=a07dd9a55779068d9409b79014a9a409&sub=CE3DA74B1A27412792DF9BB8F74E8E24 * typeScript中的函数 http://note.youdao.com/noteshare?id=adc64e95404f3c382c7549f05841c7b2&sub=65D365DE900049A28DD4697B61A5544A * 对象+继承 http://note.youdao.com/noteshare?id=7f82be21375761c13ccad1981510a614&sub=7856743A59934A59A1AA608AA78497F0 * 类的定义、继承、类里面的修饰符 http://note.youdao.com/noteshare?id=a4420ac729d8cc7c1eb72fc47198f00b&sub=399974DBD9FA4EC2A99548D8837CB61F * 静态属性 静态方法 抽象类多态 http://note.youdao.com/noteshare?id=efad91320514e4f21e07ec77a9bcfd7c&sub=DC3868B8459940CA884DC5B80EE25443 * typeScript中的接口 http://note.youdao.com/noteshare?id=ae4c7f13bec8e35b3fda4e326d7e7055&sub=6001FADE75904080A15395886608D366 * 可索引接口(数组,对象)+类类型接口 http://note.youdao.com/noteshare?id=aebf26ab922044a69cae082866ce8d86&sub=F73FB04DD10C4BA796173FBE40280B21 * 接口的继承、接口的扩展 http://note.youdao.com/noteshare?id=93e1dff481b8e299ee9c925e8e3a8b4a&sub=3C96456BFAA34C28BA6BB4E0B0C1E77B * 泛类 http://note.youdao.com/noteshare?id=6d9e0ec4cdb17249bf1bb11fae2e44ec&sub=B0C47B2089AC42E48C2E1BAAAD3FE9EF * 泛型接口 http://note.youdao.com/noteshare?id=49af2ba1bd6173467e7c7b844def959b&sub=F16F0C2857E347C0B8FB69522D5DEFA2