Typescript Union of Reference & Model #1999
-
Hi! I have a question about an issue I ran into when I have a union of reference and a model and I try to access an action that they inherited from a Base Model. To explain it more, I have a codesandbox here: https://codesandbox.io/s/inspiring-snyder-yregis?file=/src/Sample.ts
When I am accessing |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @sethdumaguin - sorry it took so long for folks to get back to you. I'm not precisely sure what's going on here, but I wonder if this is an issue where TypeScript can't appropriately infer the type from the
Here's the code sandbox: https://codesandbox.io/s/mobx-state-tree-todolist-forked-0lwr9n?file=/index.ts The only change is explicitly using baz: types.union(types.reference(Bar), Foo) as typeof Bar | typeof Foo I'm not sure if this is the fully correct way to do it, and I definitely don't love having to use Is that helpful? Did you end up finding some other solution since posting this? Would love to get a sense of where you landed on this one. |
Beta Was this translation helpful? Give feedback.
Hey @sethdumaguin - sorry it took so long for folks to get back to you.
I'm not precisely sure what's going on here, but I wonder if this is an issue where TypeScript can't appropriately infer the type from the
types.reference
call. I was able to remove the linting error by making these changes: