Vuex模块中的TypeScript错误-子模块无法分配到Vuex的索引模块中的错误

Vuex模块中的TypeScript错误-子模块无法分配到Vuex的索引模块中的错误,typescript,vuejs2,vuex,vuex-modules,Typescript,Vuejs2,Vuex,Vuex Modules,我正在使用TypeScript构建一个简单的vue项目。 我在我的vue项目中编写了vuex存储,该存储有一个名为“计算”的子模块。但是一旦创建了包含子模块的主存储,就会出现一个奇怪的错误(tserror) 以下是我的vuex代码 // calculation.ts import { Module } from 'vuex' interface ICalculationState { a: number } const calculation: Module<ICalculatio

我正在使用TypeScript构建一个简单的vue项目。 我在我的vue项目中编写了vuex存储,该存储有一个名为“计算”的子模块。但是一旦创建了包含子模块的主存储,就会出现一个奇怪的错误(tserror)

以下是我的vuex代码

// calculation.ts
import { Module } from 'vuex'

interface ICalculationState {
  a: number
}

const calculation: Module<ICalculationState, {}> = {
  namespaced: true,

  state: {
    a: 10
  }
}

export {
  calculation,
  ICalculationState
}
//calculation.ts
从“vuex”导入{Module}
接口计算状态{
a:号码
}
常数计算:模块={
名称空间:对,
声明:{
a:10
}
}
出口{
计算,
ICalculationState
}
//index.ts
从“Vue”导入Vue
从“Vuex”导入Vuex
从“/calculation”导入{calculation,icalcculationstate}
Vue.use(Vuex)
界面状态{
计算:ICalculationState
}
const store=新的Vuex.store({
模块:{
计算
}
})
导出{store,IState}
错误字符串

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>'
类型“{calculation:Module;}”不能分配给类型“ModuleTree”。
属性“calculation”与索引签名不兼容。
类型“Module”不可分配给类型“Module”。
属性“操作”的类型不兼容。
类型“ActionTree | undefined”不可分配给类型“ActionTree | undefined”。
类型“ActionTree”不可分配给类型“ActionTree”。
索引签名不兼容。
类型“Action”不可分配给类型“Action”。
类型“ActionHandler”不可分配给类型“Action”。
类型“ActionHandler”不可分配给类型“ActionHandler”。
每个签名的“this”类型不兼容。
类型“Store”不可分配给类型“Store”。
属性“registerModule”的类型不兼容。
类型“{(路径:字符串,模块:模块,选项?:模块选项|未定义):void;(路径:字符串[],模块:模块,选项?:模块选项|未定义):void;}”不能分配给类型“{(路径:字符串,模块:模块,选项?:模块选项|未定义):void;(路径:字符串[],模块:模块,选项?:模块选项|未定义):void;}”。
参数“module”和“module”的类型不兼容。
类型“Module”不可分配给类型“Module”。
属性“操作”的类型不兼容。
类型“ActionTree | undefined”不可分配给类型“ActionTree | undefined”。
类型“ActionTree”不可分配给类型“ActionTree”。
索引签名不兼容。
类型“Action”不可分配给类型“Action”。
类型“ActionHandler”不可分配给类型“Action”。
类型“ActionHandler”不可分配给类型“ActionHandler”。
类型“{}”不可分配给类型“IState”。ts(2322)
ts(9,3):“计算”在这里声明。
index.d.ts(95,3):预期类型来自属性“modules”,该属性在类型“StoreOptions”上声明

我希望红色下划线从代码所在行的下方消失。

在calculation.ts中提供IState作为“模块”中的第二个参数。 通过这种方式定义根状态,错误就消失了

const calculation: Module<ICalculationState, IState>
常数计算:模块
const calculation: Module<ICalculationState, IState>