1 原始类型
![](https://img-blog.csdnimg.cn/direct/4f09480d8f614288a0b36215031b5017.png)
//1 联合类型
let arr1: (number | string)[] = [1, 2, 3, 4]
let arr2: (number | string)[] = [1, 2, 3, 4]
let arr3: (number | string)[] = [1, 2, 3, 4]
console.log(arr1, arr2, arr3)
2类型别名 type声明类型
type ArrType = (number | string)[]
let arr11: ArrType = [1, 2, 3, 4]
let arr22: ArrType = [1, 2, 3, 4]
let arr33: ArrType = [1, 2, 3, '3']
console.log(arr11, arr22, arr33)
2.1 不同组合写法
type typeString = number | string
let arr111: typeString[] = [1, 2, '3', 4]
console.log(arr111)
2.2 不同组合写法
let strNumer: typeString = '32'
console.log(strNumer)
2.3 自定义类型
type s = string
type n = number
let str1: s = '1234'
let num1: n = 1234
console.log(str1, num1)
2.4 type 定义对象
//type 定义对象
type Person = {
username: string
password: string
}
let person: Person = {
username: 'saner',
password: '1213'
}