I'm building a simple vue-project using TypeScript. I wrote the vuex store in my vue project, and the store has a sub-module called 'calculation'. But once created the main store including sub-module, a weird error (tserror) occurs.
Following is my vuex code.
// calculation.ts
import { Module } from 'vuex'
interface ICalculationState {
a: number
}
const calculation: Module<ICalculationState, {}> = {
namespaced: true,
state: {
a: 10
}
}
export {
calculation,
ICalculationState
}
// index.ts
import Vue from 'vue'
import Vuex from 'vuex'
import { calculation, ICalculationState } from './calculation'
Vue.use(Vuex)
interface IState {
calculation: ICalculationState
}
const store = new Vuex.Store<IState>({
modules: {
calculation
}
})
export { store, IState }
Error string
Type '{ calculation: Module<ICalculationState, {}>; }' is not assignable to type 'ModuleTree<IState>'.
Property 'calculation' is incompatible with index signature.
Type 'Module<ICalculationState, {}>' is not assignable to type 'Module<any, IState>'.
Types of property 'actions' are incompatible.
Type 'ActionTree<ICalculationState, {}> | undefined' is not assignable to type 'ActionTree<any, IState> | undefined'.
Type 'ActionTree<ICalculationState, {}>' is not assignable to type 'ActionTree<any, IState>'.
Index signatures are incompatible.
Type 'Action<ICalculationState, {}>' is not assignable to type 'Action<any, IState>'.
Type 'ActionHandler<ICalculationState, {}>' is not assignable to type 'Action<any, IState>'.
Type 'ActionHandler<ICalculationState, {}>' is not assignable to type 'ActionHandler<any, IState>'.
The 'this' types of each signature are incompatible.
Type 'Store<IState>' is not assignable to type 'Store<{}>'.
Types of property 'registerModule' are incompatible.
Type '{ <T>(path: string, module: Module<T, IState>, options?: ModuleOptions | undefined): void; <T>(path: string[], module: Module<T, IState>, options?: ModuleOptions | undefined): void; }' is not assignable to type '{ <T>(path: string, module: Module<T, {}>, options?: ModuleOptions | undefined): void; <T>(path: string[], module: Module<T, {}>, options?: ModuleOptions | undefined): void; }'.
Types of parameters 'module' and 'module' are incompatible.
Type 'Module<any, {}>' is not assignable to type 'Module<any, IState>'.
Types of property 'actions' are incompatible.
Type 'ActionTree<any, {}> | undefined' is not assignable to type 'ActionTree<any, IState> | undefined'.
Type 'ActionTree<any, {}>' is not assignable to type 'ActionTree<any, IState>'.
Index signatures are incompatible.
Type 'Action<any, {}>' is not assignable to type 'Action<any, IState>'.
Type 'ActionHandler<any, {}>' is not assignable to type 'Action<any, IState>'.
Type 'ActionHandler<any, {}>' is not assignable to type 'ActionHandler<any, IState>'.
Type '{}' is not assignable to type 'IState'.ts(2322)
index.ts(9, 3): 'calculation' is declared here.
index.d.ts(95, 3): The expected type comes from property 'modules' which is declared here on type 'StoreOptions<IState>'
I want the red-underline to disappear from beneath line of where my code is.