RicoSuter/NJsonSchema

two-dimensional arrays of objects in typescript

Open

#621 opened on Feb 11, 2018

View on GitHub
 (1 comment) (0 reactions) (0 assignees)C# (550 forks)github user discovery
help wantedtype: enhancement

Repository metrics

Stars
 (1,578 stars)
PR merge metrics
 (Avg merge 39d 6h) (1 merged PR in 30d)

Description

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?

Contributor guide