RicoSuter/NJsonSchema

two-dimensional arrays of objects in typescript

开放

#621 创建于 2018年2月11日

 (1 条评论) (0 个反应) (0 位负责人)C# (549 个派生)github user discovery
help wantedtype: enhancement

仓库指标

星标
 (1,581 个星标)
PR 合并指标
 (平均合并 39天 6小时) (30 天内合并 1 个 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?

贡献者指南