xaviergonz / mobx-keystone

A MobX powered state management solution based on data trees with first class support for Typescript, support for snapshots, patches and much more
https://mobx-keystone.js.org
MIT License
549 stars 25 forks source link

Cannot find namespace "types" #154

Closed goranmandiccrs closed 4 years ago

goranmandiccrs commented 4 years ago

Hi! Loving, the library so far- trying to move away from MST into something similar but with better performance and type support, so thanks for your effort! I have an issue when trying to expose types.enum as my prop type. Here's a sandbox that illustrates my Typescrtipt issue: https://codesandbox.io/s/mobx-keystone-test-nfc5c?file=/src/index.ts

When I try importing the default mobx-keystone export, and access types as Keystone.types, I get this message: TS2694: Namespace '"C:/Users/gman/source/Zeus/node_modules/mobx-keystone/dist/index"' has no exported member 'types' How should I go about declaring enum props?

xaviergonz commented 4 years ago
  // non runtime type checked enum
  testEnum: prop<TestEnum>(),
  // runtime type checked enum
  testEnum2: tProp(types.enum(TestEnum))

the problem was trying to use types. inside the generic part

goranmandiccrs commented 4 years ago

I actually suspected this, but looking up "using dot inside generics" wasn't giving me good results, plus I couldn't figure out how to do it properly- obviously. Thank you- I'll be closing this issue now.