You can now use Object.assign(target, ...sources)
. Following your example, you could use it like this:
class Foo {
name: string;
getName(): string { return this.name };
}
let fooJson: string = '{"name": "John Doe"}';
let foo: Foo = Object.assign(new Foo(), JSON.parse(fooJson));
console.log(foo.getName()); //returns John Doe
Object.assign
is part of ECMAScript 2015 and is currently available in most modern browsers.