How describe model for Record<string, string> TS type? #2003
-
I have the following data for which I need to create a model:
The key of object in array item can be any string. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hey @KyryloSWAN - here's how I might model this out to start const TopLevelObject = types
.model("TopLevelObject", {
some: types.array(types.frozen),
}); It seems like the keys in each of your records are dynamic, and might not be suitable for "typing" in advance. In this case, the frozen type allows you to work with these objects, since they're serializable. I do this from time to time when it comes with new third party APIs, where I'm not yet sure what data I'm going to really want or need to model out from them. We sometimes store JSON blobs as |
Beta Was this translation helpful? Give feedback.
Hey @KyryloSWAN - here's how I might model this out to start
It seems like the keys in each of your records are dynamic, and might not be suitable for "typing" in advance. In this case, the frozen type allows you to work with these objects, since they're serializable.
I do this from time to time when it comes with new third party APIs, where I'm not yet sure what data I'm going to really want or need to model out from them. We sometimes store JSON blobs as
frozen
types, until we can determine a better way to model the data that we expect to use from it.