Skip to content
Discussion options

You must be logged in to vote

Hi @davidatsurge!

As you figured out TS sadly cannot figure out how to type RootStore if RootStore is used in its own definiton, so what you could do is type the parent.inbox to Instance<typeof InboxStore> instead to get around this.

Example

const RootStore = types.model({
  inbox: InboxStore,
  activeProject: types.maybeNull(
    types.reference(ProjectInbox, {
      get(identifier, parent) {
        if (parent === null) return null;

        const inbox = parent.inbox as Instance<typeof InboxStore>;

        return (
          inbox.projects.find(({ id }) => id === identifier) || (null as any)
        );
      },
      set(project) {
        return project.id;
      }
    })
  )
});

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@davidatsurge
Comment options

Answer selected by davidatsurge
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