module NamespaceX{
interface Serializable<T> {
deserialize(input: Object): T;
}
export class CustomClass implements Serializable<CustomClass>{
private property1: number;
private property2:string;
constructor(val1?:number, val2?:string){
this.property1 = val1;
this.property2 = val2;
}
deserialize(jsonData){
if (!(Array.isArray(jsonData))) {
this.Index = jsonData.index;
this.HeaderName = jsonData.headerName;
this.SortName = jsonData.sortName;
this.AllowSorting = jsonData.allowSorting;
return this;
}
else {
//Code this section to create a list
}
}
}
}
var jsonDataArray = [{ property1: 1, property2: "Test1"}, { property1: 2, property2: "Test2" }];
var collection:Array<NamespaceX.CustomClass> = new NamespaceX.CustomClass().deserialize(jsonDataArray);
I encountered the following error during compilation while using 'collection':
Type 'CustomClass' is not assignable to type 'CustomClass[]'. Property 'length' is missing in type 'CustomClass'.
How can I convert the JSON array of objects (jsonDataArray) into a list?