5

I have an custom object declared (ThreadObj) and I want to create a THREADLISTS, holding multiple arrays of Threadlist. So

Threadlist:ThreadObj[]=[];
THREADLISTS:[ThreadObj[]][ThreadObj]=[][]; //how to type and init?

The first dim is of ThreadObj[] and the second is of ThreadObj.

Cheers

3
  • Possible duplicate of Typescript - multidimensional array initialization Commented Apr 13, 2016 at 4:12
  • 1
    I've seen that thread, which unfortunately does not explain the typing question Commented Apr 13, 2016 at 5:12
  • I believe it does—ThreadObj[][]. If that's not what you mean then can you provide an example of THREADLISTS use? Maybe we're misunderstanding. Commented Apr 13, 2016 at 13:52

3 Answers 3

3

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
]

More

All in one step:

const allInOneStep: {foo:string}[][] = [
    [
        {
            foo: 'hello'
        },
        {
            foo: 'is it me'
        }
    ],
    [ 
        {
            foo: 'you are looking for'
        }
    ]
]
Sign up to request clarification or add additional context in comments.

Comments

2

Wouldn't that just be:

let arr:ThreadObj[][] = []

Comments

0

For multi-dimensional array in typescript, you can simply declare and define the variable as

let multiArr:(string|number)[][] = [["Ram","Shyam",1,2,3,"Hari"]];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.