类:类与对象字面量和接口差不多,比较两个类类型的对象时,只有实例的成员会被比较。 静态成员和构造函数不在比较的范围内。class Animal { feet: number; constructor(name: string, numFeet: number) {}}class Size { feet: number; constructor(numFeet: number) { }}let a: Animal = new Size(1); //冒号后面仅仅只是检验属性是不是一样的,不是类型let s: Size = new Animal("",0);function creat(x:Animal){} //冒号只是检验属性,不做类型检查,creat(a);creat(s);console.log(a);//Size {}console.log(s);//Animal {}-----------------------------------------------------------交叉类型:class A{ constructor(public _a1:number,public _a2:number){ this._a1 = _a1; this._a2 = _a2; } fa1(){}}interface b{ b1:number; f1();}class B implements b{ b1:number; f1(){ console.log("f1"); } fb1(){} constructor(b1:number,public _B1:number,public _B2:number){ this.b1 = b1; this._B1 = _B1; this._B2 = _B2; }}var a = new A(0,2);a._a1 = 1;var b = new B(3,4,5);console.log(a);for(let i in a){ console.log(i + "--" + typeof i);}console.log(b);for(let i in b){ console.log(i + "----" + typeof i);}var result;function extend(a : T, b : U): T & U { result = {}; for(let i in a){ //( result)[i] = ( a)[i]; //result[i] = a[i]; ( result)[i] = ( a)[i]; } for(let i in b){ if(!result.hasOwnProperty(i)){ // ( result)[i] = ( b)[i]; result[i] = b[i]; ( result)[i] = ( b)[i]; } } return result;}extend(a,b);console.log("-----------------");console.log(result);for(let i in result){ console.log(i + "----" + typeof i);}