I have a very simple class
export class Foo {
name: string;
index: number;
toFullString(): string {
return `${this.name} | ${this.index}`;
}
}
I get elements of this class from a server and cast json to this class:
.map(response => response.json() as Foo)
Now what happens is that after I call toFullString()
method it fails since this is not the "real" Foo
object as it would be in say C#.
So what is the proper way of achieving real Foo
object, preferably without the need of writing your own constructors and so on.
The type safety in TypeScript is a joke sometimes really.