ts的数组/元组/type/interface

Posted on 2020-10-25 21:09  猫头唔食鱼  阅读(2144)  评论(0编辑  收藏  举报

1.数组

let b1:number[]=[1,2,3]
let b2:string[] = ['asdf']
let b3:boolean[]=[true,false]
let b4:null[] = [null]
let b5:undefined []= [undefined]
let b6:any[] = ['asd',2]

2.元组

let b7:[string,number] = ['sdf',2]

3.type

type可以是对象形式
// type可以是对象形式的
type people = {name:string,age:number}
let b8:people = {name:'zs',age:12}
type 也可以是数组形式
// type 也可以是数组形式的
type test = [string,number]
let b9:test = ['1sdf2',1]

4.interface

// interface
interface People {
    name:string,age:number
}
let b10:People[] = [{name:'zs',age:12}]

 5.元组类型的数组

let t:[string,string,number][] = [ ['1','zs',12],['2','ls',13] ]