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

上海网站建设 迈做平面设计图的网站

上海网站建设 迈,做平面设计图的网站,wordpress cart,wordpress 抓取时间长TS系列之typeof 这里写目录标题 前言回顾#xff1a;Js中typeof的用法1、typeof的返回类型有哪些 Ts 中的 typeof 运算符作为类型判断的工具什么是 typeof#xff1f;类型保护与条件类型复杂类型 总结 前言 今天总结一下typeof相关的知识。 typeof在Js中也是常用来判断变量…TS系列之typeof 这里写目录标题 前言回顾Js中typeof的用法1、typeof的返回类型有哪些 Ts 中的 typeof 运算符作为类型判断的工具什么是 typeof类型保护与条件类型复杂类型 总结 前言 今天总结一下typeof相关的知识。 typeof在Js中也是常用来判断变量类型的关键字那么在Ts中的作用又是什么下面一起来看看。 回顾Js中typeof的用法 1、typeof的返回类型有哪些 “undefined” typeof undefined“object” typeof null或者其他任意对象至于null为什么返回的类型是object可以参考这篇文章typeof null is ‘object’ “boolean” typeof true“number” typeof 1“bigint” typeof BigInt(1)“string” typeof “symbol” typeof Symbol(1)“function” typeof function a () {}Ts 中的 typeof 运算符作为类型判断的工具 什么是 typeof typeof 是 TypeScript 中的运算符用于获取给定表达式的类型。返回一个表达式类型的字符串。 一个简单的例子 const num 1; const str Hello; console.log(typeof num); // 输出 number console.log(typeof str); // 输出 string在这个例子中typeof num 返回 “number”而 typeof str 返回 “string”很明显这和js中没有什么区别。 类型保护与条件类型 typeof 运算符的真正强大之处在于它与条件类型的结合使用。通过将 typeof 与条件类型结合我们可以在运行时对不同类型的代码进行条件分支。 举个例子 比如我们想要实现一个函数将传入的数字或者字符串类型的数据自增1并返回 function test (num: number | string): number | string {return num } //这时候ts报错提示An arithmetic operand must be of type any, number, bigint or an enum type. //意思是算术操作数的类型必须是“any”、“number”、“bigint”或枚举类型这个时候typeof就可以派上用场改造如下 function test (num: number | string): number | string {if (typeof num number) {return num;} else {return num 1;} }复杂类型 typeof 判断复杂类型时和js中的用法一样object、“function”、“symbol” 等等。 接下来我们看一下实际在开发中用的场景 1、例如我们有个对象如果对象嵌套深或者对象属性较多时那么你就可以直接用tyoeof来获取这个对象的属性中的所有类型。 const appconfig {id: 1,text: app,appName: app,appImg: https://app,appType: app,positionNum: 1,url: https://app }type appType typeof appconfig type appType {id: string;text: string;appName: string;appImg: string;appType: string;positionNum: number;url: string; } const appconfigtest: appType {} //所以你就可以直接用appType来约束新定义对象appconfigtest2、也可以获取对象中单个属性的类型 type appType typeof appconfig.appImg //type appType string3、当我想要通过函数创建并获取类的实例那么就可以通过typeof获取到class构造函数的类型 class APP {name: string;img: string;constructor (name: string, img: string) {this.name name;this.img img;} } //(parameter) CP: new (name: string, img: string) APP function createApp(CP: typeof APP, name: string, img: string) {return new CP(name, img); }总结 到这里我们就基本了解了typeof在ts中常见的一些用法 其它用法还需继续探索分享学习。
http://www.zqtcl.cn/news/199778/

相关文章:

  • 潍坊网站建设招聘官方网站建设 在线磐石网络
  • 校友网站建设开一个网站的流程
  • 商业门户网站是什么意思哪家培训机构学校好
  • 青岛企业网站制作seo排名优化培训网站
  • 2018做网站还是app上海搜索seo
  • 网站建设用模板好吗罗湖网站制作费用
  • 网站图片延时加载app推广视频
  • 郑州设计师网站个人搭建网站要多少钱
  • 网站制作成品下载wordpress怎么更改样式
  • 河北省城乡和建设厅网站首页网站维护属于什么部门
  • 西安建网站公司哪家好网站导航条设计欣赏
  • 张家港网站网络优化济南网站建设0531soso
  • 关于网站的建设深圳搜索优化排名
  • 网站建设的布局建设通破解vip
  • 怎样做公司网站介绍网站百度排名优化
  • 广州网站建设工作室招聘wordpress在哪里设置编辑器
  • 苏州网站建设功能大宗交易平台软件
  • 无域名网站 能否被百度品牌营销优化
  • 做爰全过程免费的网站视频做网站视频背景
  • 网站布局设计分析特点手机网站设计欣赏网站
  • 建设网站对服务器有什么要求灌南县规划局网站一品嘉苑规划建设
  • 常平镇仿做网站wordpress教程 菜单
  • 大气的企业网站做网站服务怎么赚钱
  • 如何用网站做淘宝客网易企业邮箱怎么修改密码
  • 白酒网站设计wordpress增加网址大全
  • 网站上图片可以做商业作品吗成都十大景观设计公司
  • 自助建站网站哪个好2017织梦网站怎么做seo
  • 佛山新网站建设咨询做业精灵官方网站
  • 大庆网站设计费用asp网站仿制
  • 革吉网站建设网页游戏中心大全