typeScript接口

十、接口

定义接口的关键词:interface

常规接口:

interface Husband {
  sex: string;
  interest: string;
}
let myHusband:Husband = {sex: '男', interest: '抽烟喝酒嚼槟榔'}
console.log(myHusband) => { sex: '男', interest: '抽烟喝酒嚼槟榔' }

规范函数类接口:

interface serchMan {
  (source: string,subString: string):boolean
}
let mysearch: serchMan
// 把接口变成函数,返回值就是布尔类型
mysearch = function (source: string,subString: string):boolean {
  let flag = source.search(subString)
  return flag != -1
}
console.log(mysearch('高、富、帅', '胖')) => false

猜你喜欢

转载自www.cnblogs.com/zjh-study/p/10650745.html
今日推荐