immutable-js / immutable-js

Immutable persistent data collections for Javascript which increase efficiency and simplicity.
https://immutable-js.com
MIT License
32.87k stars 1.78k forks source link

using typescript instance class #1996

Open sarahBuisson opened 3 weeks ago

sarahBuisson commented 3 weeks ago

When I use ImmutableJs on the instance of a ts class, I didn"t get neither a record nor a FromJs


class A {
    constructor(public a: number) {
    }
}

console.log("A",fromJS(new A(2)));

Is it possible to use instance instead of structure?

jdeniau commented 3 weeks ago

I do not have a computer right now, but FromJS will return either a List or a Map. In an object case, it will be converted to a Map, by iterating on each property. You will probably have either a Map with a as key or an empty Map if the class a prop is not iterable.