Skip to content

Commit

Permalink
Merge pull request #428 from mikecann/docs/added-ts-issue-5938
Browse files Browse the repository at this point in the history
updated readme to warn about known typescript issue
  • Loading branch information
mattiamanzati authored Oct 6, 2017
2 parents 0e0b285 + 7297dd4 commit 199c0ec
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,55 @@ const Example = types
});
```
#### Known Typescript Issue 5938
Theres a known issue with typescript and interfaces as described by: https://github.com/Microsoft/TypeScript/issues/5938
This rears its ugly head if you try to define a model such as:
```typescript
import { types } from "mobx-state-tree"

export const Todo = types.model({
title: types.string
});

export type ITodo = typeof Todo.Type
```
And you have your tsconfig.json settings set to:
```json
{
"compilerOptions": {
...
"declaration": true,
"noUnusedLocals": true
...
}
}
```
Then you will get errors such as:
> error TS4023: Exported variable 'Todo' has or is using name 'IModelType' from external module "..." but cannot be named.
Until Microsoft fixes this issue the solution is to re-export IModelType:
```typescript
import { types, IModelType } from "mobx-state-tree"

export type __IModelType = IModelType<any,any>;

export const Todo = types.model({
title: types.string
});

export type ITodo = typeof Todo.Type
```
It aint pretty, but it works.
### How does MST compare to Redux
So far this might look a lot like an immutable state tree as found for example in Redux apps, but there are a few differences:
Expand Down

0 comments on commit 199c0ec

Please sign in to comment.