数组类型
const arr = [1,2,3] // 类型推断
const numberArr:number[] = [1,2,3] // 类型注解
const strArr :string[] = ['a','b']
const undefinedArr:undefined = [undefined,undefined]
const arr :(number | string)[] = [1,'test',2]
// 对象类型的数组
const objArr:{name:string,age:number}[] = [
{name:'test',age:18},
{name:'test1',age:18}
]
// 对象类型的数组,简易写法
type a = {name:string,age:number}
const objArr:a[] = [
{name:'test',age:18},
{name:'test1',age:18}
]
class b = {
name:string;
age:number;
}
const objArr:b[] = [
{name:'test',age:18},
{name:'test1',age:18}
]