接口类型 作用:给对象约束属性和方法 基础语法: interface 接口名 { 属性名:类型 } 接口名称推荐以I开头 接口声明后,直接使用接口名称作为变量类型
interface person { name: string age: number gender: string sayHi: () => void } const p1:person = { name:'yansunda', age:18, gender:'男', sayHi(){ console.log("qq"); } } p1.sayHi();
继承
interface Istudent extends person { score: number, sleep: () => void } const s1: Istudent = { name: 'yansunda', age: 18, gender: '男', sayHi() { console.log("qq"); }, score:90, sleep(){ console.log('is sleep'); } } s1.sayHi() s1.sleep()
标签:TypeScript,console,log,继承,接口,sleep,interface,sayHi From: https://www.cnblogs.com/yansunda/p/18440426