Skip to content

Commit

Permalink
types: remove ComponentCustomProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
kiaking committed Apr 20, 2020
1 parent caac029 commit 29d26cd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
21 changes: 21 additions & 0 deletions README.md
Expand Up @@ -44,6 +44,27 @@ app.use(store)
app.mount('#app')
```

### Typings for `ComponentCustomProperties`

Vuex 4 removes its global typings for `this.$store` within Vue Component due to solving [issue #994](https://github.com/vuejs/vuex/issues/994). When using TypeScript, you must provide your own augment declaration.

Please place the following code in your project to have `this.$store` working.

```ts
// vuex-shim.d.ts

declare module "@vue/runtime-core" {
// Declare your own store states.
interface State {
count: number
}

interface ComponentCustomProperties {
$store: Store<State>;
}
}
```

## Known issues

- The code is kept as close to Vuex 3 code base as possible, and there're plenty of places where we should refactor. However, we are waiting for all of the test cases to pass before doing so (some tests require Vue 3 update).
Expand Down
4 changes: 0 additions & 4 deletions types/test/vue.ts
Expand Up @@ -10,7 +10,3 @@ const store = new Vuex.Store({
const app = createApp({
store
});

const vm = app.mount('#el')

vm.$store.state.value;
6 changes: 0 additions & 6 deletions types/vue.d.ts
Expand Up @@ -10,9 +10,3 @@ declare module "@vue/runtime-core" {
store?: Store<any>;
}
}

declare module "@vue/runtime-core" {
interface ComponentCustomProperties {
$store: Store<any>;
}
}

0 comments on commit 29d26cd

Please sign in to comment.