How to add complex interface as types.array to some property ? #1916
-
for example i have this interface export interface SOF_MANAGEPASS {
/* Navigation properties */
SOF_SCATBYMAIL_SUBFORM: SOF_SCATBYMAIL[];
SOF_MSGSBYMAIL_SUBFORM: SOF_MSGSBYMAIL[];
SOF_BANRBYMAIL_SUBFORM: SOF_BANRBYMAIL[];
SOF_DATABYMAIL_SUBFORM: SOF_DATABYMAIL[];
SOF_CUSTSUPBYMAIL_SUBFORM: SOF_CUSTSUPBYMAIL[];
SOF_EPARTS_SUBFORM: SOF_EPARTS[];
SOF_PASSCOND_E_SUBFORM: SOF_PASSCOND_E[];
/* Properties */
EMAIL: string;
USERLOGIN: string;
PASSWORD: string;
NEWPASSWORD: string;
IPADDRESS: string;
PUSHTOKEN: string;
PINCODE: string;
SENDPINCODE: string;
FORGOTPASSWORD: string;
OTP: string;
USERDISPLAY: string;
RESTLOGIN: string;
WINDOWSLOGIN: string;
EXTFILENAME: string;
FILTER: string;
CSNAME: string;
CSDES: string;
CSTYPE: string;
BRANCHNAME: string;
BRANCHDES: string;
NUM: number;
PLNAME: string;
PLDES: string;
AGENTCODE: string;
AGENTNAME: string;
HPURL: string;
} can i make something like this ? const SomeNameStore = types
.model("SomeName", {
formStore: types.optional(types.array(SOF_MANAGEPASS), []),
...
}) or do i most create this interface as a model ? |
Beta Was this translation helpful? Give feedback.
Answered by
EmilTholin
May 31, 2022
Replies: 1 comment
-
Hi @AlonGvili! Using a TS You could instead create a model with all your properties and derive an 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, ... } |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
EmilTholin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @AlonGvili!
Using a TS
interface
as argument fortypes.array
will sadly not be possible, asinterface
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 ofSnapshotIn
that you can use elsewhere in your code: