1.属性接口
- 对自定义方法中传入参数的约束
interface FullName {
firstName: string;
secondName: string;
age?: number;
}
function printName(name: FullName) {
console.log(name.firstName + '--' + name.secondName);
}
const obj = {
firstName: '张',
secondName: '三'
}
printName(obj);
2.函数类型接口
- 对方法传入的参数以及返回值进行约束
interface encrypt {
(key: string, value: string): string;
}
var md5: encrypt