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

getParent not useable in child view with TypeScript when adding actions to parent #1851

Open
patrickschmelter opened this issue Jan 5, 2022 · 1 comment
Labels
help/PR welcome Help/Pull request from contributors to fix the issue is welcome Typescript Issue related to Typescript typings

Comments

@patrickschmelter
Copy link

patrickschmelter commented Jan 5, 2022

Bug report

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

Sandbox link or minimal reproduction code
Click here

Describe the expected behavior
I should be able to properly type the return value of getParent when using a model with actions as parent.

Describe the observed behavior
As long as there are no actions defined in the parent model, getParent accepts the type and everything works as expected. As soon as I add any action to the parent model, its type becomes any. If on the other hand I remove the getParent function from the child model after adding an action to the parent model, the parent type will be correct again. There seems to be something wrong when using both getParent and actions on the parent combined. Individually I see no errors.

Edit: same thing happening with getParentOfType

No action:
noaction

No view:
noview

In combination:
any1
any2

Edit:
Working when getParent is used externally, but this solution will not be maintainable for large applications
externally

@coolsoftwaretyler
Copy link
Collaborator

Hey @patrickschmelter - I'm sorry it took so long for us to get back to you. Thanks for the details. I'm going to label this as a TypeScript issue, which we know is a big challenge for the codebase overall.

Once we figure out where this lands in priorities, hopefully I'll have some updates. In the meantime, we would welcome any PRs to improve TS typings.

@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 27, 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