TypeScript 如何获取一个数组的具体类型
eg:
const arr1 = [1,2,3] -> number
const arr2 = ['1','2','3'] -> string
const arr3 = [{data:1},{data:2},{data:3}] -> {data:number}
我现在有一个写法是通过typeof
,但是总感觉哪里不对(~ ̄▽ ̄)~
eg:
type a1 = typeof arr1[0]
type a2 = typeof arr2[0]
type a3 = typeof arr3[0]
希望不吝赐教!