属性类型接口
interface FullName {
firstName: string;
secondName?: string;
}
function printName(params:FullName) {
console.info(params.firstName+":"+params.secondName)
}
let jack = {age: 10,firstName:"Li"};
printName(jack);
函数类型接口
定义了函数的参数。包括入参和出参。
interface encrypt {
(val:string, salt:string):string; // 入参val和salt,返回字符串
}
let md5:encrypt;
md5 = function(val:string, salt:string){
return "";
}
可索引类型接口
interface Users {
[index: number]: string; // [index: string]: string;
}
let u:Users = ["Li", "Zhang"]; // {name:"Li", age:10}
console.info(u[0])
类类型接口
interface Animal {
name: string;
setName(n: string):void;
}
class Person implements Animal {
...
}