Skip to content

MSTMap does not have observe method, but IMSTMap does #2275

@n9

Description

@n9

Bug report

  • I've checked documentation and searched for existing issues and discussions
  • I've made sure my project is based on the latest MST version
  • Fork this code sandbox or another minimal reproduction.

Sandbox link or minimal reproduction code

https://codesandbox.io/p/devbox/nameless-shadow-987q7v?workspaceId=ws_V6MwkdyBVdYpA4KMGgF9f5

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

const Tweet = types
  .model("Tweet", {
    body: types.string,
    read: false, // automatically inferred as type "boolean" with default "false"
  })
  .actions((tweet) => ({
    toggle() {
      tweet.read = !tweet.read;
    },
  }));

const TwitterStore = types.model("TwitterStore", {
  tweets: types.map(Tweet),
});

// create an instance from a snapshot
const twitterStore = TwitterStore.create();

twitterStore.tweets.observe((c) => {}); // 🐞 twitterStore.tweets.observe is not a function

Describe the expected behavior

It will not crash.

Describe the observed behavior

It crashes with twitterStore.tweets.observe is not a function.

Thoughts

I assume the cause is that the ObservableMap no longer have the observe method.

PS: Maybe MSTMap should also implement IMSTMap?

Metadata

Metadata

Assignees

No one assigned

    Labels

    TypescriptIssue related to Typescript typingsbugConfirmed bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions