Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type issue when assigning a store with a reference #1764

Open
3 tasks done
RickLucassen opened this issue Aug 17, 2021 · 2 comments
Open
3 tasks done

Type issue when assigning a store with a reference #1764

RickLucassen opened this issue Aug 17, 2021 · 2 comments
Labels
help/PR welcome Help/Pull request from contributors to fix the issue is welcome Typescript Issue related to Typescript typings

Comments

@RickLucassen
Copy link

Bug report

  • I've checked documentation and searched for existing issues
  • 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/s/mobx-state-tree-todolist-forked-o9yj3

Describe the expected behavior
In the example we're defining a root store with another store as a property. That store has a property of type array of a model.
When that model doesn't have a types.reference present everything is fine. However, when the model does have a types.reference present typescript complains about an incorrect type.

Typescript should resolve these types correctly.

Describe the observed behavior
As seen in the rootStore, where there is a version with and without the reference, the one with the reference generates a typescript error about the someModel type not matching.

@RickLucassen
Copy link
Author

It seems that wrapping the createTodoStoreWithReference with castToSnapshot does make it work. Would this be the proposed solution?

Still strange that without the castToSnapshot there is a difference in behavior between the two stores (with and without a reference).

@coolsoftwaretyler
Copy link
Collaborator

Hey @RickLucassen - sorry it took so long for anyone to get back to you here. We are trying to give some more care and attention here to MobX-State-Tree

I don't know for 100% sure that castToSnapshot is the best case solve, but if it did help your issue, that makes sense. There are some known issues with the TypeScript inferences in MST, and we're highly interested in fixing that.

If you're still having the problem, or if you solved it elsewise, I'd love to hear what worked for you. Or if you moved on, no worries.

For now, I'll leave this issue and label with with TS and help/PR welcome. Hopefully we can find some ways to improve this moving forward.

@coolsoftwaretyler coolsoftwaretyler added help/PR welcome Help/Pull request from contributors to fix the issue is welcome Typescript Issue related to Typescript typings labels Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help/PR welcome Help/Pull request from contributors to fix the issue is welcome Typescript Issue related to Typescript typings
Projects
None yet
Development

No branches or pull requests

2 participants