类型别名:又称为自定义类型,为任意类型起别名。
使用场景: 当同一类型(复杂)被多次使用时,可以通过该类型别名,简化该类型的使用。
type CumtomArr = (number|string) [];
let arr:CumtomArr = [1,2,"str"];
//类型别名相当于声明了一个变量
type obj = {
name:string,
age:number
}
type Method = "get"|"post"|"put"|"delete";
function http(method:Method){
console.log(method)
}
http("get")