Closed misaeldossantos closed 3 years ago
this.todos = [{name: 'test 1'}, {name: 'test 2'}]
I assume you want the todos array to be an array of Todo instances, so you'd need to do
this.todos = [new Todo({name: 'test 1'}), new Todo({name: 'test 2'})]
// or
this.todos = [{name: 'test 1'}, {name: 'test 2'}].map(data => new Todo(data))
mobx-keystone (unlike mst) does not do implicit conversions from snapshots to instances automatically in order to be more explicit and have more specific TS typings.
No plains to add this feature?
In order to implement it the use of tProp then would need to be required (so it actually knows what kind of model the array is made of). You can see https://github.com/xaviergonz/mobx-keystone/issues/123 for more details
When I try to assign a js object to an attribute of the model, the object is not instantiated, so when I try to call a method, an exception is raised because it does not exist.
Ex.:
it raise this error: TypeError: todos.todos[0].setName is not a function because class was not instantiate. But if I do: this.todos = [new Todo({name: 'test 1'}), new Todo({name: 'test 2'})] works.
It is too bad, because deep attrs (with array) is hard to instantiate manually, especially after calling an api...