RicoSuter/NJsonSchema

two-dimensional arrays of objects in typescript

オープン

#621 opened on 2018/02/11

 (1 件のコメント) (0 件のリアクション) (0 人の担当者)C# (549 件のフォーク)github user discovery
help wantedtype: enhancement

Repository metrics

Stars
 (1,581 個のスター)
PR merge metrics
 (平均マージ 39d 6h) (30d で 1 merged PR)

説明

C# code such as

[DataContract]
public class Foo {
  [DataMember] public int FooNum {get;set;}
}

[DataContract]
public class Bar {
  [DataMember] public Foo[][] Foos {get;set;}
}

The issue is when creating the init method for Bar, the generated typescript will look like

...
if (data["Foos"] && data["Foos"].constructor === Array) {
  this.foos = [];
  for (let item of data["Foos"])
    this.foos.push(item); // <------- problem here, not calling Foo.fromJS
}
...

For a one-dimensional array, the typescript correctly uses this.foos.push(Foo.fromJS(item)). This isn't high priority for me since I was able to remove two-dimensional arrays and instead create an intermediate class. I don't know how much you want to fix here, support many array dimensions?

コントリビューターガイド