Vuex + 打字稿 [英] Vuex + Typescript
问题描述
我正在将一个 JavaScript 项目转换为 TypeScript.但是,当我尝试让 Vue 使用 Vuex 时出现类型错误.
I am converting a JavaScript project to TypeScript. However I am getting a type error when trying to make Vue use Vuex.
import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);
问题是 vuex 不像 vuejs 那样提供类型定义?
It looks like the problem is that vuex does not provide type definitions like vuejs does?
因为我还要设置
"allowSyntheticDefaultImports": true
在我的 tsconfig.json 中.
in my tsconfig.json.
如何解决这个问题,让 Vue.use 接受 Vuex 作为正确的类型?
How can I solve this problem and make Vue.use accept Vuex as the correct type?
推荐答案
我希望我有更好的答案,但我最终删除了 node_modules 并重新安装了它们.版本之间似乎不匹配.
I wish I had an better answer, but I ended up deleting node_modules and reinstall them. It appeared to be a mismatch between versions.
在我快速安装和升级包后,Vue/Vuex 自己的类型确实处理了所有事情.
Vue / Vuex own typings did take care of everything after I ran a quick package install and upgrade.
这篇关于Vuex + 打字稿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!