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