TypeScript:不介绍了,可以认为是一门基于JavaScript的编程语言。(ts会被编译成js文件)
环境配置:
1、安装最新的node
2、打开命令行窗口,运行以下语句:
npm install -g typescript
新建一个.ts文件
在命令行窗口运行:
tsc 文件名.ts
这个ts文件就会在同级目录下生成一个同名的.js文件。
学习笔记一:
TypeScript基础类型:
// the demo is about typescript variable
let a:boolean = false
let b:number = 26
let c:string = "zack"
let d:string = `my name is: ${c} and i'm ${b} years old`
let e:string[] = ["TypeScript","SpringBoot"]
// 元组
let f:[string,number] = ["hello",22]
// 枚举
enum Color {red, yellow, blue}
let g:Color = Color.yellow
// 枚举2
enum Type {red = 1,yellow = 2, blue}
let h:Type = Type.yellow
let i:Type = Type.blue
// 任意值类型
let j:any = "test"
j = 3
// viod类型
// 方法中使用,该方法不返回参数
// 在变量中声明,该变量只能赋值undefined和null
// undefined和null是所有类型的子类型
function test():void{
console.log("函数不会返回任何信息!")
}
let k:void = null
// never类型
// never类型是所有类型的子类型
// 所有类型均不是never类型的子类型
// never类型是那些总是会抛出异常或根本就不会有返回值的函数表达式或箭头函数表达式的返回值类型;
// 变量也可能是 never类型,当它们被永不为真的类型保护所约束时。
// 人类的本质是“复读机”。上面两行为“字都认识系列”,我并不清楚这个类型的存在意义
console.log("第一个是布尔型: " + a)
console.log("第二个类型是数字: " + b)
console.log("第三个类型是字符串:" + c)
console.log("第四个类型是组合字符串: " + d)
console.log("第五个类型是字符串数组: " + e)
console.log("第六个类型是元组: " + f)
console.log("第七个类型是枚举: " + g)
console.log("第八个类型是枚举二:" + h)
console.log("第九个类型是枚举二: " + i)
console.log("第十个类型是任意类型:" + j)
console.log("第十一个类型是一个空类型: " + k)