Feature: Manually install vuex/types/vue.d.ts · Issue #994 · vuejs/vuex (original) (raw)

This is a breaking change

What problem does this feature solve?

With module merging in TS, we can override module interfaces. However it is limited, in the case of the Vuex types it's impossible to compose full typing layer in components.

If we make it optional to install vuex/types/vue.d.ts then we can do our own manual declaration. Which will enable fully typed structures. I would also rename to vuex/types/install.d.ts

What does the proposed API look like?

Once we allow custom installation we can do something similar to this to enable full typing layer.

import Vue from 'vue' import * as Vuex from 'vuex' import { RootState } from 'store/types'

Vue.use(Vuex);

export class Store { store: Vuex.Store;

static instance: Store;

constructor() { this.store = new Vuex.Store{ strict: true }); }

get() { return this.store } }

declare module "vue/types/options" { interface ComponentOptions { store?: Vuex.Store; } }

declare module "vue/types/vue" { interface Vue { $store: Vuex.Store; } }

export default Store