Returning Specific Non MST Type From Map in Typescript #1768
Unanswered
mashaalmemon
asked this question in
Q&A
Replies: 1 comment
-
I posted an similar issue.. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm considering using Mobx-State-Tree in an app where all of our types are already defined using typescript.
For example I have types already defined for different data entities, and these were define prior to considering Mobx-State-Tree for our global store:
I understand that to use Mobx-State-Tree to model my entities I'll need to use mobx
types
:And I intend to use a map to take advantage of references to keep my data normalized:
When observing changes to the
users
map in react, and getting back an object, I understand from a Typescript typing perspective, I will get back aInstance<typeof User>
typed object back.My main question is, is there a way I can set it such that I get a
IUserRecord
typed object back instead. For my purposes they will be almost equivalent in terms of the data it holds (other than theid
field). Yes I can do explicit casting in typescript everytime I observe theusers
map, but I'm hoping there is a better way.Beta Was this translation helpful? Give feedback.
All reactions