FredyC
FredyC

Reputation: 4067

Direct or indirect reference in TypeScript 3.5

We are using a library mobx-state-tree which include fairly complex TypeScript declarations that are hard to decipher for me.

Either way, it seems that some change happened between TS 3.4 and 3.5 that caused a strange issue.

enter image description here

I have prepared a minimal reproduction in a repository: https://github.com/FredyC/mobx-state-tree-ts3.5

I am aware this is probably a very specific problem that needs a deep dive. Would appreciate at least the right direction what change in TS 3.5 could be causing an issue like that.

Update

Based on the answer https://stackoverflow.com/a/56781615/902813 I tweaked the example in a repo and got a similar error. It seems like that mobx-state-tree could be abusing some bug in TS which got fixed in 3.5 and now it breaks stuff.

enter image description here

Upvotes: 1

Views: 198

Answers (1)

Mu-Tsun Tsai
Mu-Tsun Tsai

Reputation: 2534

I cannot be certain what is the deep cause of your problem just by a quick look of your code, but in your minimal example, TS is complaining about get root() method in BaseModel.ts referring itself in its return value (as for where, it might take a while to find, as mobx-state-tree is quite big), so you need to add a type to it by writing get root(): TRootModel and then your project will compile just fine.

Upvotes: 1

Related Questions