【问题标题】:Vuex typescript commit typeVuex 打字稿提交类型
【发布时间】:2022-01-05 07:16:16
【问题描述】:

我正在尝试使用 typescript+vue3 转换一些 vue 项目

现在在我的商店里> actions.js

我有一个函数:

const SET_TEST = ({commit}, val: string | number) => {
commit('SET_TEST', val);

}

export default {
    SET_TEST
}

现在,{commit} 给了我错误消息:Binding element 'commit' implicitly has an 'any' type
我的问题是,这里{commit} 的类型应该是什么?

【问题讨论】:

    标签: typescript vue.js vuex


    【解决方案1】:

    commit 不应显式键入,整个函数应:

    const SET_TEST: Action<MyStoreType, MyStateType> = ({commit}, val: string | number) => ...
    

    【讨论】:

      猜你喜欢
      • 2018-01-09
      • 2020-11-18
      • 2020-03-16
      • 1970-01-01
      • 2020-05-05
      • 2018-04-04
      • 2021-06-14
      • 2017-06-12
      • 2021-11-26
      相关资源
      最近更新 更多