RicoSuter/NJsonSchema
two-dimensional arrays of objects in typescript
Aperta
#621 aperta il 11 feb 2018
help wantedtype: enhancement
Metriche repository
- Star
- (1581 stelle)
- Metriche merge PR
- (Merge medio 39g 6h) (1 PR mergiata in 30 g)
Descrizione
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?