编辑代码

const hello:string = "hellow world"
console.log(hello)

// 数组 泛型
const list:Array<number> = [1]
const list1:[] = []
console.log(list)

// 元组
let tb:[string,number];

// 枚举
enum color {
    red,
    green
}
let c:color = color.red;
console.log(c) // 索引位置

// void 表示没有返回值
function hellow():void {
    console.log('void ----')
    // return 111 // 报错
}

// any 类型为任意类型可跳过编译阶段类型检查
let x:any = 1 // 数字类型
x =  'this is string' // 字符串类型

// 声明多种类型
let moreType: number | string | null | undefined;

// never 类型

// 变量声明

// 1、如果变量没有声明类型,那么该变量是任意类型即 any  
var a = 1
// 2、注意:变量中不能出现 name 否则会与 DOM 中的全局 window 对象下的 name 属性出现了重名。
// 3、类型断言 Type Assertion 可以手动指定一个值的类型,允许变量从一个类型更改为另一种类型
var str = '1';
var str2:number = <number> <any> str //str、str2 是 string 类型