I have defined a class as follow:
class Foo {
p1: string;
p2: string;
a_method(): string{
return p1+p2;
}
};
And I have a service to return JSON object which corresponding to the Foo.
var foo: Foo= <Foo> restService.getOne(1);
So the above code work ok, but I'm wondering if the following code will work:
foo.a_method();
My understanding is that when the JSON is converted to a javascript, it shouldn't have any method attached to it. Unless typescript does something when casting, the code above shouldn't be working.
Also I'm wondering in javascript in general, how should I implement this cast.