2016-04-13 55 views
1

カスタムオブジェクトが宣言されています(ThreadObj)。スレッドリストの複数の配列を保持してスレッド定義を作成します。従ってtypescript異なる型を持つ多次元配列

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

第1の淡色はThreadObj []であり、第2の淡色はThreadObjである。

乾杯

+0

[Typescript - 多次元配列の初期化]の可能な複製(http://stackoverflow.com/questions/30144580/typescript-multidimensional-array-initialization) –

+0

このスレッドを見ましたが、残念ながら入力の質問 –

+0

を説明していません私はそれが~ThreadObj [] 'と信じています。それがあなたが意味するものではないなら、あなたは 'スレブライズ 'の使用例を提供できますか?たぶん私達は誤解しているかもしれません。 –

答えて

2

例:ワンステップで

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' 
     } 
    ] 
] 
1

はそれだけではないでしょう:

let arr:ThreadObj[][] = []