Our C# application provides a number of JSON web-services for the web app client to consume. Currently we generate that JSON reasonably manually through recursive object-to-JSON-dictionary-representation calls.
We're gradually implementing parts of our web app in TypeScript - we'd like to have TypeScript interfaces to define the shape of the JSON data the client code should expect to receive from the server.
Is there a way to automatically generate the TypeScript data contract interface definitions at compile time, based on the C# JSON service implementation?
For example, the C# code generating the JSON currently looks something like this:
public class ConcreteObj
{
public string SimpleProperty;
public ConcreteObj[] Children;
}
public static IDictionary<string, object> ConvertToScriptValue(ConcreteObj obj)
{
IDictionary<string, object> result = new Dictionary<string, object>();
result["simpleProperty"] = obj.SimpleProperty; // string
result["children"] = Array.ConvertAll(obj.Children, ConvertToScriptValue); // ConcreteObj array
return result;
}
We'd like to see TypeScript similar to the following:
interface ConcreteObj {
simpleProperty: string;
children: ConcreteObj[];
}