TypeScript调用接口
TypeScript学习笔记
调用接口
interface Girl { name : string; age : number; bust : number; }
const girl={ name:'史迪奇', age : 0, bust : 999
}
const screenResume = (girl:Girl) => { girl.age < 24 && girl.bust >= 90 && console.log(girl.name + '进入战场') girl.age >= 24 || girl.bust < 90 && console.log(girl.name + '已死亡') }
const getResume = (girl:Girl) => { console.log(girl.name+'的年龄'+girl.age) console.log(girl.name+'的实验品编号'+girl.bust) }
screenResume(girl) getResume(girl)
|
接口不仅能限制对象还可以限制类
interface Girl { name : string; age : number; bust : number; waistline ?: number; [propname:string]:any; say():string }
interface syp extends Girl{ syp():string }
const girl={ name:'史迪奇', age : 0, bust : 626, waistline:999, sex:'男', say(){ return "毁灭吧" } }
class sdq implements Girl{ name:'鲁本' age : 0 bust : 625 waistline:999 sex:'男' say(){ return "毁灭吧" } }
const screenResume = (girl:Girl) => { girl.age < 24 && girl.bust >= 90 && console.log(girl.name + '进入战场') girl.age >= 24 || girl.bust < 90 && console.log(girl.name + '已死亡') }
const getResume = (girl:Girl) => { console.log(girl.name+'的年龄'+girl.age) console.log(girl.name+'的实验品编号'+girl.bust) girl.waistline && console.log(girl.name+'的战斗力'+girl.waistline) girl.sex && console.log(girl.name+'的性别'+girl.sex) }
screenResume(girl) getResume(girl)
|
作者: 我叫史迪奇
本文来自于:
https://sdq3.link/TypeScript-interface.html博客内容遵循 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 协议