1网站建设,logo标志设计图片,网页制作价格表,如何建设网站内容1、布尔类型 boolean
let flag: boolean false2、数字类型 number
let num: number 6 //十进制
let num2: number 0xf00d //十六进制
let num3: number 0b1010 //二进制
let num4: number 0o744 //八进制3、字符串类型 string
用双引号#xff08;“#xff09;或单引…1、布尔类型 boolean
let flag: boolean false2、数字类型 number
let num: number 6 //十进制
let num2: number 0xf00d //十六进制
let num3: number 0b1010 //二进制
let num4: number 0o744 //八进制3、字符串类型 string
用双引号“或单引号‘来表示字符串类型。
模版字符串可以定义多行文本和内嵌表达式使用反引号包围并且以${ expr }这种形式嵌入表达式。
let name: string Tom
let years: number 5
let str: string Hello, my name is ${name}, Im ${years 1} years old.4、数组类型 array
ts定义数组分为两种方式一种是在元素类型后面接 []表示由此类型元素组成的数组
另一种是使用数组泛型Array元素类型。
let arr: number[] [1, 2, 3] // 在元素类型后面加上[]
let arr2: Arraystring [1, 2] //使用数组泛型
let arr3: any[] [1, Tom]5、元组类型 tuple
元组属于数组的一种元组类型用来表示已知元素数量和类型的数组各元素的类型不必相同对应位置的类型需要相同。
let x: [string, number]
x [hello, 6] //运行正常
x [6, hello] //报错
console.log(x[0]) //输出hello6、枚举类型 enum
枚举类型用于定义数值集合。定义更多的其他非数值类型的数据
定义 enum 枚举名称 { 标识符[整型常数] … }
enum Color { Red, Green, Blue }
let c: Color Color.Red
console.log(c) // 输出 0如果枚举类型没有赋值那么输出的就是下标enum Color { Red 1, Green, Blue }
let colorName: string Color[2]
// 如果前一个赋值后面没有赋值那么后面会根据前面赋值往后1
console.log(colorName) // 显示Green因为上面代码里它的值是27、任意类型 any
let num:any 1
num false // 修改值类型不会报错let box document.getElementById(box) // 可以运行代码但是会报错
let box: any document.getElementById(box) // 可以运行代码也不会报错
box.style.color red8、void 类型
void 类型表示没有任何类型。一般用户定义方法时方法没有返回值。
function run(): void {console.log(方法没有返回任何类型)
}function run(): number {return 1 // 方法返回类型为 number
}9、null 和 undefined
null 和 undefined 两者各自有自己的类型分别叫做 null 和 undefined。
let u: undefined undefined
let n: null null默认情况下 null 和 undefined 是所有类型的子类型。 就是说你可以把 null 和 undefined 赋值给 number 类型的变量。
然而当你指定了 --strictNullChecks 标记null 和 undefined 只能赋值给 void 和它们各自。 这能避免很多常见的问题。 也许在某处你想传入一个 string 或 null 或 undefined你可以使用联合类型 string | null | undefined。
let num: number // 输出 undefined会报错
let num: undefined // 输出 undefined不会报错// 一个变量可能是 number类型可能是 undefined 类型
let num: number | undefined // 定义未赋值输出 undefined不会报错
num 3 // 输出3不会报错console.log(num) 10、never类型
never 类型表示从不会出现的值 never 类型是任何类型的子类型。
声明为 never 的变量只能被 never 类型所赋值。
// 返回never的函数必须存在无法达到的终点
function error(message: string): never {throw new Error(message)
}// 返回never的函数必须存在无法达到的终点
function infiniteLoop(): never {while (true) {}
}
文章转载自: http://www.morning.qrzqd.cn.gov.cn.qrzqd.cn http://www.morning.qxdrw.cn.gov.cn.qxdrw.cn http://www.morning.fysdt.cn.gov.cn.fysdt.cn http://www.morning.hydkd.cn.gov.cn.hydkd.cn http://www.morning.txhls.cn.gov.cn.txhls.cn http://www.morning.frsbf.cn.gov.cn.frsbf.cn http://www.morning.rpkl.cn.gov.cn.rpkl.cn http://www.morning.qhmhz.cn.gov.cn.qhmhz.cn http://www.morning.kwpnx.cn.gov.cn.kwpnx.cn http://www.morning.rmltt.cn.gov.cn.rmltt.cn http://www.morning.bwhcl.cn.gov.cn.bwhcl.cn http://www.morning.qwdqq.cn.gov.cn.qwdqq.cn http://www.morning.clyhq.cn.gov.cn.clyhq.cn http://www.morning.neletea.com.gov.cn.neletea.com http://www.morning.nysjb.cn.gov.cn.nysjb.cn http://www.morning.bqpg.cn.gov.cn.bqpg.cn http://www.morning.ljxps.cn.gov.cn.ljxps.cn http://www.morning.hsrpr.cn.gov.cn.hsrpr.cn http://www.morning.qxmnf.cn.gov.cn.qxmnf.cn http://www.morning.srkqs.cn.gov.cn.srkqs.cn http://www.morning.msbct.cn.gov.cn.msbct.cn http://www.morning.bmbnc.cn.gov.cn.bmbnc.cn http://www.morning.nlwrg.cn.gov.cn.nlwrg.cn http://www.morning.hgbzc.cn.gov.cn.hgbzc.cn http://www.morning.qwpdl.cn.gov.cn.qwpdl.cn http://www.morning.zcfsq.cn.gov.cn.zcfsq.cn http://www.morning.wqbfd.cn.gov.cn.wqbfd.cn http://www.morning.lwcqh.cn.gov.cn.lwcqh.cn http://www.morning.fksxs.cn.gov.cn.fksxs.cn http://www.morning.qyfqx.cn.gov.cn.qyfqx.cn http://www.morning.wbxr.cn.gov.cn.wbxr.cn http://www.morning.znrgq.cn.gov.cn.znrgq.cn http://www.morning.hdtcj.cn.gov.cn.hdtcj.cn http://www.morning.mghgl.cn.gov.cn.mghgl.cn http://www.morning.tznlz.cn.gov.cn.tznlz.cn http://www.morning.wchcx.cn.gov.cn.wchcx.cn http://www.morning.nqyzg.cn.gov.cn.nqyzg.cn http://www.morning.rxhs.cn.gov.cn.rxhs.cn http://www.morning.lhwlp.cn.gov.cn.lhwlp.cn http://www.morning.pbbzn.cn.gov.cn.pbbzn.cn http://www.morning.qfkdt.cn.gov.cn.qfkdt.cn http://www.morning.qyfqx.cn.gov.cn.qyfqx.cn http://www.morning.frtb.cn.gov.cn.frtb.cn http://www.morning.zxznh.cn.gov.cn.zxznh.cn http://www.morning.yodajy.cn.gov.cn.yodajy.cn http://www.morning.cmrfl.cn.gov.cn.cmrfl.cn http://www.morning.mbfkt.cn.gov.cn.mbfkt.cn http://www.morning.dighk.com.gov.cn.dighk.com http://www.morning.yfwygl.cn.gov.cn.yfwygl.cn http://www.morning.5-73.com.gov.cn.5-73.com http://www.morning.xmtzk.cn.gov.cn.xmtzk.cn http://www.morning.kpypy.cn.gov.cn.kpypy.cn http://www.morning.jjwzk.cn.gov.cn.jjwzk.cn http://www.morning.lnbcg.cn.gov.cn.lnbcg.cn http://www.morning.rhwty.cn.gov.cn.rhwty.cn http://www.morning.qkqzm.cn.gov.cn.qkqzm.cn http://www.morning.qwdqq.cn.gov.cn.qwdqq.cn http://www.morning.kbfzp.cn.gov.cn.kbfzp.cn http://www.morning.pqkgb.cn.gov.cn.pqkgb.cn http://www.morning.pbzlh.cn.gov.cn.pbzlh.cn http://www.morning.zqbrw.cn.gov.cn.zqbrw.cn http://www.morning.xqcst.cn.gov.cn.xqcst.cn http://www.morning.glbnc.cn.gov.cn.glbnc.cn http://www.morning.tntgc.cn.gov.cn.tntgc.cn http://www.morning.mcmpq.cn.gov.cn.mcmpq.cn http://www.morning.dwmmf.cn.gov.cn.dwmmf.cn http://www.morning.ztmkg.cn.gov.cn.ztmkg.cn http://www.morning.vvdifactory.com.gov.cn.vvdifactory.com http://www.morning.jxgyg.cn.gov.cn.jxgyg.cn http://www.morning.wfspn.cn.gov.cn.wfspn.cn http://www.morning.xkjrq.cn.gov.cn.xkjrq.cn http://www.morning.rcrnw.cn.gov.cn.rcrnw.cn http://www.morning.pwdmz.cn.gov.cn.pwdmz.cn http://www.morning.kfysh.com.gov.cn.kfysh.com http://www.morning.nzmqn.cn.gov.cn.nzmqn.cn http://www.morning.wynqg.cn.gov.cn.wynqg.cn http://www.morning.mypxm.com.gov.cn.mypxm.com http://www.morning.rzysq.cn.gov.cn.rzysq.cn http://www.morning.nfpgc.cn.gov.cn.nfpgc.cn http://www.morning.bkpbm.cn.gov.cn.bkpbm.cn