Skip to content

How to add complex interface as types.array to some property ? #1916

Answered by EmilTholin
AlonGvili asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @AlonGvili!

Using a TS interface as argument for types.array will sadly not be possible, as interface is purely a TS concept that is removed entirely at compile time.

You could instead create a model with all your properties and derive an interface from that with the help of SnapshotIn that you can use elsewhere in your code:

import { SnapshotIn, types } from "mobx-state-tree";

const SofManagepassModel = types.model("SofManagepassModel", {
  /* Navigation properties */
  // ...

  /* Properties */
  EMAIL: types.string
  // ...
});

interface SOF_MANAGEPASS extends SnapshotIn<typeof SofManagepassModel> {} // => { EMAIL: string, ... }

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by EmilTholin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants