Skip to content

Using mobx-state-tree $nonEmptyObject typescript error? #1699

Answered by cmdcolin
cmdcolin asked this question in Q&A
Discussion options

You must be logged in to vote

Applying a really helpful suggestion from #1524 we can get

export const Hello = types.model("Hello", {
  name: types.string,
});
export const HelloWithSnapshotProcessor = types.snapshotProcessor(Hello, {
  postProcessor: (snap) => {
    const { name, ...rest } = snap as Omit<typeof snap, symbol>;
    if (!name) {
      return rest;
    }

    return snap;
  },
});

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@cmdcolin
Comment options

@EmilTholin
Comment options

@cmdcolin
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by cmdcolin
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