How do I cast a JSON object to a TypeScript class?
@lebyy▲ 0 net votes
Problem: I read a JSON object from a remote REST server. This JSON object has all the properties of a TypeScript class (by design). How do I cast that received JSON object to a type var? I don't want to populate a TypeScript var (i.e. have a constructor that takes… Fix (from the top answer): You can't simple cast a plain-old-JavaScript result from an Ajax request into a prototypical JavaScript/TypeScript class instance. There are a number of techniques for doing it, and generally involve copying data. Unless you create an instance of the class, it won't have any methods or properties. It will remain a…