mobxjs / mobx-state-tree

Full-featured reactive state management without the boilerplate
https://mobx-state-tree.js.org/
MIT License
6.94k stars 640 forks source link

RootStore type becomes "any" the moment we call a RootStore model action using yield on a child model action #2040

Open cpintos-sc opened 1 year ago

cpintos-sc commented 1 year ago

Bug report

Sandbox link or minimal reproduction code Here is the repro

Describe the expected behavior The typings should not become any and there shouldn't be any circular reference error.

Describe the observed behavior The problem starts when using yield with a RootStore action within a child model. I do not have a problem getting the RootStore or even executing it's actions, it just happens when using yield with an async function. See line 13, 14 and 15 of the RootStore.ts file.

coolsoftwaretyler commented 1 year ago

Hey @cpintos-sc - thanks for filing this issue and putting together the reproduction! Very helpful.

I think this may be related to https://github.com/mobxjs/mobx-state-tree/issues/1851 although I'm not 100% sure if it's exactly the problem.

Either way, we do know that our TypeScript updates really need to be improved. I'm not exactly sure when we'll be fixing it, but it's top of the list. Sorry for the inconvenience at the moment.

If you're interested in pitching in, we'd gladly accept some assistance. But no worries if you just wanted to let us know and hopefully we can resolve this for ya in the coming months.

Anoninz commented 8 months ago

I have a workaround to solve this issue. It's declare StoreInstance by handwriting instead of use Instance

type RootStoreInstance = {
  SomeStore: SomeStoreInstance
}

and use this type in getRoot<RootStoreInstance>(self)

rkz98 commented 8 months ago

@Anoninz workaround worked for me. Thank u.