Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translating a model #8

Open
djMax opened this issue Jul 20, 2020 · 3 comments
Open

Translating a model #8

djMax opened this issue Jul 20, 2020 · 3 comments

Comments

@djMax
Copy link

djMax commented Jul 20, 2020

We're evaluating using this library for a large project and I'm having some trouble getting started. My existing model is fairly simple:

export const FeatureStoreModel = types
  .model('Feature', {
    status: types.optional(
      types.enumeration<LoadStatus>(Object.values(LoadStatus)),
      LoadStatus.None,
    ),
    features: types.array(types.frozen<Feature>()),
  })
  .actions((self) => ({
    importFeatures: (features: Feature[]) => {
      self.status = LoadStatus.Complete;
      self.features.replace(features);
    },
  }));

LoadStatus is a TS enumeration, and Feature is a fairly complex TypeScript interface which comes from a automated api-type-generator (i.e. I don't want to have to copy it or modify it). When I do what I thought was the simple translation:

class FeatureStore {
  @enumeration(LoadStatus) status
  @array(@frozen(Feature)) features
}

I get an error that "Feature is used as a type when a value is expected." I assume that it's because Feature is supposed to be annotated with decorators just like FeatureStore is?

@farwayer
Copy link
Owner

Remove @ before frozen. It should be @array(frozen(Feature))

@farwayer
Copy link
Owner

Ah, Is Feature not MST type? In this situation you should not pass it as arg for frozen. mst-decorators has very basic TS defs for now. All improvements are welcome. For now you can only do @array(frozen()) features

@djMax
Copy link
Author

djMax commented Jul 20, 2020

yes, exactly. I figured that was the problem, though I wasn't sure what to do about it. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants