I am trying to introduce immutable.js to an Angular2 project and I am having trouble using typescript classes with immutable.js.
I am trying to deep convert a mutable object coming from a class into an immutable one using Immutable.fromJS function. Unfortunately, although fromJS works fine on json objects, it does nothing (or throws when trying to call .toJS() to the generated object) if an object coming from a class is given.
class Person {
public firstName: string;
}
let p = new Person();
p.firstName = 'Mike';
console.log(p);
let immutablePersonFail = Immutable.fromJS(p);
console.log(Immutable.Map.isMap(immutablePersonFail)); // returns false
let immutablePersonSuccess = Immutable.fromJS({firstName: 'Nick'});
console.log(Immutable.Map.isMap(immutablePersonSuccess)); // returns true
here is jsbin demonstrating the issue: https://jsbin.com/yefeha/edit?js,console