sanlangguo / learn-notes

学习笔记
16 stars 1 forks source link

TS 常用小技巧 #26

Open sanlangguo opened 2 years ago

sanlangguo commented 2 years ago

TS 常用类型

数组对象

JS 

const data = [{
   name: '三郎过',
   age: 29,
   books: null 
}]

TS

interface JsonValue {
    [x: string]: string | number | null
}

const data: JsonValue[] = [{
   name: '三郎过',
   age: 29,
   books: null 
}]

对象子属性是数组

JS

const obj = {
    name: '三郎过',
    t: {
        age: 29,
         books: null
    }
}

TS

const obj: Record<string, any> = {
    name: '三郎过',
    t: [{
        age: 29,
        books: null
    }]
}