当前位置: 首页 > news >正文

自做头像的网站网站制作技巧

自做头像的网站,网站制作技巧,关键词seo优化排名公司,WordPress动漫源码1.TS 类型断言定义 把两种能有重叠关系的数据类型进行相互转换的一种 TS 语法#xff0c;把其中的一种数据类型转换成另外一种数据类型。类型断言和类型转换产生的效果一样#xff0c;但语法格式不同。 2.TS 类型断言语法格式 A 数据类型的变量 as B 数据类型 。 A 数据类…1.TS 类型断言定义 把两种能有重叠关系的数据类型进行相互转换的一种 TS 语法把其中的一种数据类型转换成另外一种数据类型。类型断言和类型转换产生的效果一样但语法格式不同。 2.TS 类型断言语法格式 A 数据类型的变量 as B 数据类型 。 A 数据类型和 B 数据类型必须具有重叠关系。 3.TS 类型断言使用规则和场景 1如果 AB 如果是类并且有继承关系 【 extends 关系】无论 AB 谁是父类或子类 A 的对象变量可以断言成 B 类型B 的对象变量可以断言成A类型 。但注意一般在绝大多数场景下都是把父类的对象变量断言成子类。 class People {public myusername!: string;public myage!: number;public address!: stringpublic phone!: stringconstructor() {}eat() {}step() {console.log(Peoplestep);} }class Stu extends People {public username!: stringpublic age!: number;public address!: stringconstructor(username: string, age: number, address: string, public phone: string) {super();this.address address;}study() {} }let people new People()//let result people as Stu;// 类型断言 正确 let result Stupeople;// 类型转换 正确 result.study();let stu new Stu(wangwu, 23, 北京, 123) let result2 stu as People;// 正确2如果 AB 如果是类但没有继承关系 两个类中的任意一个类的所有的 public 实例属性【不包括静态属性】加上所有的 public 实例方法和另一个类的所有 public 实例属性加上所有的 public 实例方法完全相同或是另外一个类的子集则这两个类可以相互断言否则这两个类就不能相互断言。 // 类型断言中的不能相互重叠问题: // 两个类之间断言的规则: // 两个类中任意一个的属性和方法是另一个类的属性和方法完全相同或子集则这两个类可以相互断言 // 否则这两个类就不能相互断言class People {constructor(public username: string, public age: number,public address: string) {} }class Stu {public username!: stringpublic age!: number;public address!: stringpublic phone!:string;constructor(username: string, age: number, address: string) {this.address address;} }let people new People(wangwu, 23, beijing) let stuedConvert people as Stu; let stu new Stu(wangwu, 23, 北京) let peopledConvert stu as People;3如果 A 是类B 是接口并且 A 类实现了 B 接口【implements】则A 的对象变量可以断言成 B 接口类型同样 B 接口类型的对象变量也可以断言成A类型 。 interface People {username: string, age: number, address: string, phone: string }class Stu implements People {public username!: stringpublic age!: number;public address!: stringpublic phone!: stringpublic kk() {}constructor(username: string, age: number, address: string) {this.address address;} }let people: People { username: wangwu, age: 23, address: 11, phone: 111 } let result people as Stu;//正确 let result2 Stupeople;// 类型转换 正确let stu new Stu(wangwu, 23, 北京) stu as People;// 正确 4如果 A 是类B 是接口并且 A 类没有实现了 B 接口则断言关系和第2项的规则完全相同。 interface People {username: string, age: number, address: string, phone: string }class Stu {public username!: stringpublic age!: number;public address!: stringpublic phone!: stringpublic kk() {}constructor(username: string, age: number, address: string) {this.address address;} }let people: People { username: wangwu, age: 23, address: 11, phone: 111 } let result people as Stu;//正确let stu new Stu(wangwu, 23, 北京) stu as People;// 正确 5如果 A 是类B 是 type 定义的数据类型 type 定义的数据类型是引用数据类型例如 Array, 对象不能是基本数据类型例如 stringnumber,boolean并且有 A 类实现了 B type 定义的数据类型【 implements】则 A 的对象变量可以断言成 B type 定义的对象数据类型同样 B type 定义的对象数据类型的对象变量也可以断言成 A 类型 。 type People {username: string, age: number, address: string, phone: string }class Stu implements People {public username!: stringpublic age!: number;public address!: stringpublic phone!: stringconstructor(username: string, age: number, address: string) {this.address address;} }let people: People { username: wangwu, age: 23, address: 11, phone: 111 } let result people as Stu;//正确let stu new Stu(wangwu, 23, 北京) stu as People;// 正确 6如果 A 是类B 是 type 定义的数据类型并且 A 类没有实现 B type定义的数据类型则断言关系和第2项的规则完全相同。 type People {username: string, age: number, address: string, phone: string } class Stu {public username!: stringpublic age!: number;public address!: stringconstructor(username: string, age: number, address: string) {this.address address;} }let people: People { username: wangwu, age: 23, address: 11, phone: 111 } let result people as Stu;//正确let stu new Stu(wangwu, 23, 北京) stu as People;// 正确 7如果 A 是一个函数上参数变量的联合类型例如 string |number那么在函数内部可以断言成 string 或number 类型。 function selfMutiply(one: string | number) {one as number 3; }8多个类组成的联合类型断言 例如let vechile: Car | Bus | Trunck。 vechile 可以断言成其中任意一种数据类型。 例如 vechile as Car vechile as Bus vechile as Trunck 。 class Vechile {static count: number 3;public brand: string;public vechileNo: string;public days: number;public total: number 0;public deposit: number;constructor(brand_: string, vechileNo_: string, days_: number, deposit_: number) {this.brand brand_;this.vechileNo vechileNo_;this.days days_;this.deposit deposit_;}public calculateRent() {}payDesposit() {}public safeShow() {} }class Car extends Vechile {public type: string;constructor(brand_: string, vechileNo_: string, days_: number,deposit_: number, type_: string) {super(brand_, vechileNo_, days_, deposit_);this.type type_;}public getPriceByType() {}public calculateRent() {}public checkIsWeigui(isOverWeight: boolean) {} }class Bus extends Vechile {public seatNum: numberconstructor(brand_: string, vechileNo_: string, days_: number,deposit_: number, seatNum_: number) {super(brand_, vechileNo_, days_, deposit_);this.seatNum seatNum_;}public getPriceBySeatNum() {}public checkIsOverNum(isOverWeight: boolean) {} }class Truck extends Vechile {ton!: numberconstructor(brand_: string, type_: string,days_: number, deposit_: number, ton_: number) {super(brand_, type_, days_, deposit_);this.ton ton_;}checkIsOverWeight(isOverWeight: boolean) {}CalRentPrice() {}public calRent() {}public calDesposit() {} }class Customer {rentVechile(vechile:Bus | Truck | Car) {// 下面进行断言、转换//Busvechile 等同 vechile as Bus//vechile as unknown//vechile.calculateRent()//(vechile as Bus).checkIsOverNum(false)} }9任何数据类型都可以转换成 any 或 unknown 类型**any 或 unknown 类型也可以转换成任何其他数据类型。 function add(one: string | number, two: string | number) {return one as any two as any }console.log(add(3, 5)) console.log(add(3, 5))4.类型断言存在的意义和应用场景 场景1顾客在执行汽车租赁项目租赁价格计算方法中调用每一个类的独有方法时使用 场景2对象中的 Symbol 数据类型取值问题 场景3加法计算巧用 as any。 let symid Symbol(objid) let obj { [symid]: 101, username: wangwu, age: 23 } let username obj[username] //let objidobj[symid]//类型“symbol”不能作为索引类型使用 // 解决: let objid obj[symid as any] //let objid2 obj[symid as unknown]//类型“unknown”不能作为索引类型使用 //let symidunknown symid as unknown// 可以转换成unknown,正确 脚踏实地行海阔天空飞
http://www.pierceye.com/news/186260/

相关文章:

  • 网站核验点网站自己怎么做的
  • 购物网站建设平台canvas可画网页版
  • 企业信息平台系统网站推广优化建设
  • 免费网站模板制作自助建站上建的网站免费吗
  • 深圳市网站建设外包公司门户网站代码结构
  • 昆明做网站建设找谁最新版在线 网
  • 东昌府聊城网站建设网站广告做的好的企业案例分析
  • asp三层架构做网站网站开发前端基础
  • 医院网站建设方案策划书把网站做成app的软件下载
  • 网站建设实践报告3000字wordpress消息提示插件
  • 网站制作的评价标准做网站后台需要什么
  • 学院网站建设服务宗旨实惠的网站建设产品
  • 网站改名 备案影视制作
  • 网站开发亿码酷技术网站建设选谋者
  • 智能家居网站模板怎样做网站标题优化
  • 深圳制作网站制作公司哪家好最简洁 wordpress主题
  • 重庆忠县网站建设公司推荐国内公关公司
  • 给彩票网站做代理违法吗wordpress文章与页面关联
  • 网站标题加后缀模拟ip访问网站
  • 临清网站建设费用什么是网络营销的基础
  • 街道办的网站由谁做的企业首次建设网站的策划流程
  • 优化大师免费版下载一键优化下载安装
  • 网站建设近五年出版的书籍甘肃省工程建设信息官方网站
  • 杭州网站现场备案项目营销策划方案
  • 网站打包成app软件php网站 上传
  • 行业网站建设策划方案系部网站开发计划书
  • 建设部网站投诉核查做网站一般几个人
  • 360网站推广官网网址怎样在网站做咨询医生挣钱
  • 重庆市建设银行网站一站式网站建设有哪些
  • 自学设计软件的免费网站免费ppt模板简约