[英]typescript multidimensional array with different types
我有一个自定义的 object 声明 (ThreadObj),我想创建一个 THREADLISTS,持有多个 arrays 的 Threadlist。 所以
Threadlist:ThreadObj[]=[];
THREADLISTS:[ThreadObj[]][ThreadObj]=[][]; //how to type and init?
第一个 dim 是 ThreadObj[],第二个是 ThreadObj。
干杯
范例:
type ThreadObj = {foo:string}
type ThreadList = ThreadObj[];
type ThreadListList = ThreadList[];
const obj: ThreadObj = {
foo: '123'
}
const singleDim: ThreadList = [
obj
]
const multiDim: ThreadListList = [
singleDim,
singleDim
]
一站式:
const allInOneStep: {foo:string}[][] = [
[
{
foo: 'hello'
},
{
foo: 'is it me'
}
],
[
{
foo: 'you are looking for'
}
]
]
那不是吗:
let arr:ThreadObj[][] = []
对于typescript中的多维数组,可以简单的声明和定义变量为
let multiArr:(string|number)[][] = [["Ram","Shyam",1,2,3,"Hari"]];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.