Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make IModelType exported to avoid TS Errors #256

Closed
xaviergonz opened this issue Jul 19, 2017 · 10 comments
Closed

Make IModelType exported to avoid TS Errors #256

xaviergonz opened this issue Jul 19, 2017 · 10 comments

Comments

@xaviergonz
Copy link
Contributor

xaviergonz commented Jul 19, 2017

While trying a simple test with TS 2.4.1:

import { types } from 'mobx-state-tree';

export const AreaProperties = types.model('AreaProperties', {
}, {});

I got a typescript error saying:

TS4023: Exported variable 'AreaProperties' has or is using name 'IModelType' from external module "....../node_modules/mobx-state-tree/dist/types/complex-types/object" but cannot be named.

The fix is easy (but right now kind of ugly), I need to add an import like this:

import { IModelType } from 'mobx-state-tree/dist/types/complex-types/object';

and then the error will disappear, but I'd rather import it from 'mobx-state-tree' directly.

@xaviergonz
Copy link
Contributor Author

xaviergonz commented Jul 19, 2017

Same with ISimpleType (if I add a property like x: types.number) and ISnapshottable (if I add a property that is based in another model such as obj: AreaProperties) actually

@mattiamanzati
Copy link
Contributor

Hi, thanks for reporting! They are now exported as well on the main package and should be out with next release! :)
Can you please check if its ok by cloning the repository locally, building and npm install from local folder?
Thanks for your time! :)

@mattiamanzati mattiamanzati reopened this Jul 19, 2017
@xaviergonz
Copy link
Contributor Author

seems to work :) the only annoying thing is WebStorm trying to optimize out the "unused" imports, but I guess that's a WebStorm problem (and using // noinspection ES6UnusedImports fixes it)

@xaviergonz
Copy link
Contributor Author

xaviergonz commented Jul 20, 2017

Ok actually another one when using types.map

import { IExtendedObservableMap } from 'mobx-state-tree/dist/types/complex-types/map'

PS: are maps required to have strings as keys or can they be numbers?

@mattiamanzati
Copy link
Contributor

I updated the master branch, please check if its ok so I will cut a minor release :)

They only support strings as now due to a mobx limitation to support IE.
It will be supported on MobX 4, so keep tuned. :)
Most likely will be implemented in MST after as a separate type that will (most likely types.kvp = key value pair) that will be an observable map and serialized as an array of object with key and value properties.

@xaviergonz
Copy link
Contributor Author

xaviergonz commented Jul 20, 2017

Looking good! (though I didn't test all possible types so far)

Damned IE :) Am I right that the json serialization (snapshot) of a map then is a plain object?

@mattiamanzati
Copy link
Contributor

@xaviergonz Yep, it is!

@mweststrate
Copy link
Member

@xaviergonz Please note to always import from mobx-state-tree never from a specific file inside the dist build. That will mess up packaging etc. Sadly there is a popular VSCode plugin that does that by default :(

@mweststrate
Copy link
Member

@mattiamanzati btw, we could more often use type instead of interface, which don't have the constraint they need to be exported :)

@xaviergonz
Copy link
Contributor Author

@mweststrate thanks, I wanted to, but I didn't have much of a choice :) I plan to fix the imports in my code as soon as the fix is out in npm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants