Skip to content

Instantly share code, notes, and snippets.

@jdmichaud
Last active December 18, 2017 17:29
Show Gist options
  • Save jdmichaud/81e4f6fc6f7c0f82877f069d7928c094 to your computer and use it in GitHub Desktop.
Save jdmichaud/81e4f6fc6f7c0f82877f069d7928c094 to your computer and use it in GitHub Desktop.
// npm install --save lodash @types/lodash
import * as lodash from 'lodash';
class A {
public property: number;
}
class B {
public a: A;
}
class C {
constructor(object: C) {
(Object as any).assign(this, object);
}
public name: string;
public b: B;
}
const c = new C(JSON.parse('{ "name": "Billy", "b": { "a": { "property": 42 } } }'));
const b = c.b;
console.log(JSON.stringify(c)); // {"name":"Billy","b":{"a":{"property":42}}}
lodash.merge(c, JSON.parse('{ "b": { "a": { "property": 666 } } }'));
console.log(JSON.stringify(c)); // {"name":"Billy","b":{"a":{"property":666}}}
console.log(b === c.b); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment