mobxjs / mst-gql

Bindings for mobx-state-tree and GraphQL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

types.late always typed as any

sebikap-gm2 opened this issue · comments

Hi there!
I'm having an issue, where all the generated models which reference other models are typed as
someProp: types.union(types.undefined, types.late((): any => SomeNameModel))
The issue I'm having is with the "any" literal typing, which instead of typing "someProp" as being of type "SomeNameModel", it gets typed as "any".

While digging into the code, I understand that when generated with the command gets run with "--format ts" attribute, ": any" type is hardcoded. Link to file.

I'm not sure if this was intended to solve this issue, but it does not seems to be causing that problem.

Could that "any" typing be removed?

My assumption is that it's to work around circular dependencies, as recommended in mobx-state-tree's docs: https://mobx-state-tree.js.org/tips/circular-deps

Their reasoning is that since the data is type-safe at runtime, casting the any back into your model type is OK. Though from a cleanliness perspective it's not ideal.