My background is in C# where I have experience working in a dynamic and reflective manner. Now, I am transitioning to TypeScript for writing a class and trying to apply similar principles.
To provide context, I am converting an existing application into a web app. The backend developer is reluctant to make significant changes to support JSON effectively. Hence, the plan is to send back JSON data structured like this:
{
Columns: [
{
"ColumnName": "ClientPK",
"Label": "Client",
"DataType": "int",
"Length": 0,
"AllowNull": true,
"Format": "",
"IsReadOnly": true,
"IsDateOnly": null
}
],
Rows:[
0
]
}
I intend to create an Angular class that extends Response and includes a specialized method called JsonMinimal that can interpret this type of data and return an object accordingly.
import { Response } from "@angular/http";
export class ServerSource
{
SourceName: string;
MoreItems: boolean;
Error: string;
ExtendedProperties: ExtendedProperty[];
Columns: Column[];
}
export class ServerSourceResponse extends Response
{
JsonMinimal() : any
{
return null;
}
}
While I understand that StackOverflow does not provide complete solutions, I seek guidance on structuring a dynamic response within TypeScript without encountering errors. This particular developer has numerous server-side methods, all returning strings in either JSON or XML format. My goal is to merge column and row data to build a comprehensive object that encapsulates these combined units.
An example scenario post-mapping the data to a basic object would involve:
var data = result.JsonMinimal() as LoginResponse; // Mapping the object correctly once the required data is integrated.
var pk = data.ClientPK.Value;