I have:
Hey,
Lets assume i have a an "EventModel" and i wish to use this model as a type outside the scope of mst and inside a function of some sort with typescript. is there a way of doing it without typing an identical interface to eventModel?
for further clarification, if i have a model as follow
const A = types.model(
a: types.string,
b: types.number
)
is there a way to generate the identical copy of a none mst model
as follow from the mst model
interface B{
a: string,
b: number
}
interface B extends Instance<typeof A> {}
where instance has to be imported from mobx-state-tree
@xaviergonz Is there any possibility to transform interfaces to mst models? In other word, can I define a mst model with interface but mst types?
you'd need to create a tool that uses the typescript parser to parse the abstract tree of the interface and then generate a js file that generates the appropriate mst code out of it
actually that could be a cool idea for a typescript transformer, but still you'd loose optional defaults
I met some trouble when I was trying to transform type into interface, can you tell me what's wrong?
This is the codesandbox, please look at the schema.ts.
that's because the object your are declaring is actually a SnapshotOut, not an Instance
in the docs there are more details about the differences between SnapshotIn, SnapshotOut and Instance
https://github.com/mobxjs/mobx-state-tree/blob/master/README.md#using-a-mst-type-at-design-time
thanks for the help
no problem 馃榿
Most helpful comment
interface B extends Instance<typeof A> {}where instance has to be imported from mobx-state-tree