Skip to content

Commit

Permalink
Merge pull request #15 from byte-fe/develop
Browse files Browse the repository at this point in the history
fix(type): Fix the type definition of useStore that Model({...}) return
  • Loading branch information
ArrayZoneYour authored Dec 28, 2018
2 parents 9ee9d94 + 566de55 commit a64fa1e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ Running demo
```
git clone https://github.com/byte-fe/react-modelx.git
cd react-model/example
yarn
yarn dev
npm i
npm run initial
npm run dev
```

install package
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"author": "ArrayZoneYour <[email protected]>",
"license": "MIT",
"dependencies": {
"immer": "^1.9.3"
"immer": "^1.9.3",
"react": "^16.7.0-alpha.2",
"react-dom": "^16.7.0-alpha.2"
},
"devDependencies": {
"@types/react": "^16.7.11",
"@types/react-dom": "^16.0.11",
"react": "^16.7.0-alpha.2",
"react-dom": "^16.7.0-alpha.2",
"typescript": "^3.2.1"
},
"repository": {
Expand Down
7 changes: 1 addition & 6 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface Models {
[name: string]: ModelType
}

type ModelType<InitStateType, ActionKeys> = {
type ModelType<InitStateType = {}, ActionKeys = {}> = {
actions: {
[P in keyof ActionKeys]: Action<InitStateType, ActionKeys[P], ActionKeys>
}
Expand All @@ -36,8 +36,3 @@ type getConsumerActionsType<T> = {
}

type Get<T, N extends keyof T> = T[N]

type UseStore<K extends keyof M, M extends Models> = (
name: K,
models?: M
) => [Get<M[K], 'state'>, getConsumerActionsType<Get<M[K], 'actions'>>]
5 changes: 4 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ const registerModel = <M extends Models>(models: M) => {
...models
}
return { useStore } as {
useStore: UseStore<keyof M, M>
useStore: <K extends keyof M>(
name: K,
models?: M
) => [Get<M[K], 'state'>, getConsumerActionsType<Get<M[K], 'actions'>>]
}
}

Expand Down

0 comments on commit a64fa1e

Please sign in to comment.