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

建设银行信用卡被钓鱼网站迅速让一个wordpress

建设银行信用卡被钓鱼网站,迅速让一个wordpress,竞价排名适合百度这样的网络平台吗,广点通广告平台ts的常用类型前言安装ts常见类型原始类型 、数组、 any变量上的类型注解函数对象类型联合类型类型别名接口接口和类型别名的对比前言 typescript中为了使编写的代码更规范,更有利于维护,增加了类型校验,安装 安装 typescript npm i typescr…

ts的常用类型

  • 前言
  • 安装
  • ts常见类型
    • 原始类型 、数组、 any
    • 变量上的类型注解
    • 函数
    • 对象类型
    • 联合类型
    • 类型别名
    • 接口
      • 接口和类型别名的对比


前言

typescript中为了使编写的代码更规范,更有利于维护,增加了类型校验,

安装

安装 typescript
npm i typescript -g
运行
tsc hello.ts

ts常见类型

原始类型 、数组、 any

类型举例描述
string“Hello word”表示字符串
number42所有的数字,类型都是 number
booleantrue 和 false布尔值
Array①var arr:number[]=[11,22,33] ② var arr:Array=[11,22,33];数组
anylet obj: any = { x: 0 };当你不希望一个值导致类型检查错误的时候,就可以设置为 any

变量上的类型注解

当你使用 const、var 或 let 声明一个变量时,你可以选择性的添加一个类型注解,显式指定变量的类型

let myName: string = "Alice";

函数

参数类型注解(Parameter Type Annotations)

当你声明一个函数的时候,你可以在每个参数后面添加一个类型注解,声明函数可以接受什么类型的参数。参数类型注解跟在参数名字后面:

function greet(name: string) {console.log("Hello, " + name.toUpperCase() + "!!");//当参数有了类型注解的时候,TypeScript 便会检查函数的实参:
}

对象类型

function printCoord(pt: { x: number; y: number }) {console.log("The coordinate's x value is " + pt.x);console.log("The coordinate's y value is " + pt.y);
}
printCoord({ x: 3, y: 7 });

可选属性:对象类型可以指定一些甚至所有的属性为可选的,你只需要在属性名后添加一个 ? :

function printName(obj: { first: string; last?: string }) {console.log(obj.last.toUpperCase());//可能为undefined,所以要先判断下if (obj.last !== undefined) {// OKconsole.log(obj.last.toUpperCase());}
}
// Both OK
printName({ first: "Bob" });
printName({ first: "Alice", last: "Alisson" });

联合类型

基于已经存在的类型构建新的类型,现在把它们组合在一起。

function printId(id: number | string) {console.log("Your ID is: " + id);
}
// OK
printId(101);
// OK
printId("202");
// Error
printId({ myID: 22342 });
// Argument of type '{ myID: number; }' is not assignable to parameter of type 'string | number'.
// Type '{ myID: number; }' is not assignable to type 'number'.
// 因为定义的参数类型为数字或者字符串,对象不符合条件

注:必须对每个联合的成员都是有效的。举个例子,如果你有一个联合类型 string | number , 你不能使用只存在 string 上的方法:

function printId(id: number | string) {console.log(id.toUpperCase());// Property 'toUpperCase' does not exist on type 'string | number'.// Property 'toUpperCase' does not exist on type 'number'.//解决方法 用typeof 先判断一下类型,在执行方法
}

类型别名

顾名思义,一个可以指代任意类型的名字。

type Point = {x: number;y: number;
};// Exactly the same as the earlier example
function printCoord(pt: Point) {console.log("The coordinate's x value is " + pt.x);console.log("The coordinate's y value is " + pt.y);
}printCoord({ x: 100, y: 100 });

你可以使用类型别名给任意类型一个名字,举个例子,命名一个联合类型:

type ID = number | string;

接口

interface Point {x: number;y: number;
}function printCoord(pt: Point) {console.log("The coordinate's x value is " + pt.x);console.log("The coordinate's y value is " + pt.y);
}printCoord({ x: 100, y: 100 });

接口和类型别名的对比

  • 相同点: 都可以给对象指定类型
  • 不同点:
    • 接口:只能为对象指定类型
    • 类型别名:不仅可以为对象指定类型,实际上可以为唯衣类型指定别名
http://www.sczhlp.com/news/56296/

相关文章:

  • 网站后台管理系统功能北京城建设计院网站
  • 网站提示危险网站如何建小企业网站
  • 导航网站开发谁能低价做网站支付接口
  • 微网站建设价格ajax网站
  • 网站速度测速网页制作企业网站作业
  • 网站首页布局修改做网站千篇一律
  • 阿里云主机建网站中国最大的企业培训公司
  • 利用Switch上的Smile Basic软件控制手柄播放音乐
  • 甘南网站建设公司ppt模板免费下载网站不用登录
  • 网站文章内容优化方案网站正能量就是一打开全是的
  • 网站建成怎么仿制一个网站
  • 昆山公司网站建设电话湘潭网站建设 都来磐石网络
  • 可以做mc图片的网站平阳门户网站建设
  • 云南省住房和城乡建设厅勘察设计处网站帮别人做网站的公司
  • 一流的低价网站建设单页网站做cpa
  • 网站做的漂亮的企业做婚介网站可行性报告
  • 石家庄网站建设案例重庆设计公司网站
  • 深圳h5网站制作微网站是什么时候创建的
  • 望周知
  • 网站平台建设呈现全新亮点哪里设计网页便宜
  • 山东网站设计织梦做淘宝客网站
  • php开源企业网站珠海响应式网站制作
  • html5网站多少钱wordpress模板是什么
  • 专业建设目标企业网站seo案例
  • 0116_原型模式(Prototype)
  • 营销专业就业前景襄阳网站seo技巧
  • 后台企业网站模板wordpress 查询系统
  • 大美工设计网站官网建立网站的流程是什么
  • 网络营销网站 优帮云华为手机应用引擎
  • dw做六个页面的网站万网域名注册后怎么样做网站