mobx-state-tree-ts
Better typescript type definitions for mobx-state-tree
The only difference with the public API of mobx-state-tree is how models are created.
Basically instead of this:
; const Book = types// views, actions, etc;
You write this:
; // always import stuff from here instead of mobx-state-tree const Book = types // views, actions, etc ;
While the syntax looks a bit worse, thanks to that change you get a much improved typescript experience for mobx-state-tree.
Also whenever you want to assign a submodel snapshot to a model variable / map / array you will need to either use create to create a node instance from the snapshot (recommended) or typecast it to typeof submodel.Type
.
For example:
; // always import stuff from here instead of mobx-state-tree const Book = types ; const TwoBooks = types ; // create a twoBooks instance, then... // either this (recommended)twoBooksbook1 = Book; // or thistwoBooksbook1 = title: 'some book' as typeof BookType;