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);
It looks like the problem is that vuex does not provide type definitions like vuejs does?
Because I also have to set
"allowSyntheticDefaultImports": true
in my tsconfig.json.
How can I solve this problem and make Vue.use accept Vuex as the correct type?
Vuex provides its typings so you can use TypeScript to write a store definition. You don't need any special TypeScript configuration for Vuex. Please follow Vue's basic TypeScript setup to configure your project.
Now that Vue officially supports TypeScript, it's easy to create TypeScript projects from scratch using only the Vue CLI without any third-party libraries. However, neither the official Vue docs nor the TypeScript docs include all the information you need to get started.
Pinia has a Simpler API than Vuex Pinia's API is simpler and more intuitive than Vuex. Getting started with state management is much easier even for a junior developer as a lot of boilerplate code that needed to be written between every state change in Vuex has now been removed in Pinia.
ts files. import Vue from 'vue'; import Vuex from 'vuex'; Vue. use(Vuex); export default new Vuex. Store({ state: { Languages: [], IsStudent: false, }, mutations: { setLanguages: (state, values) => { values.
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 own typings did take care of everything after I ran a quick package install and upgrade.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With