安装/初次使用
安装ts(node环境下)
npm i typescript -g
版本号,生成配置文件
tsc -v
生成jsconfig.json配置文件
tsc --init
新建1.ts
const str:string = "1"
console.log(str)
编译文件
tsc -w / tsc --watch
或
tsc 1.ts
生成一个1.js
执行js文件
node 1.js
基本类型
字符串类型,数字类型,布尔类型
const str = "1"
const num: number = 1
const binary: number = 0b1010
const octal: number = 0o744
const hex: number = 0xf00d
const infinityNumber: number = Infinity
const notANumber: number = NaN
const boo1: boolean = true
const boo2: boolean = false
注意:
const boo3: boolean = new Boolean(1)
const boo4: Boolean = new Boolean(1)
null undefined
const n: null = null
const u: undefined = undefined
void空值类型
严格模式下:
let v1: void = null
let v2: void = undefined
非严格模式下:
let v1: void = null
let v2: void = undefined
const fn1 = (): void => { }