Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vuex + Typescript

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);

enter image description here

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?

like image 267
Schoening Avatar asked Aug 02 '17 11:08

Schoening


People also ask

Does Vuex support TypeScript?

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.

Can I use TypeScript with Vue?

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.

Is pinia better than Vuex?

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.

How do I access Vuex in TS file?

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.


1 Answers

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.

like image 140
Schoening Avatar answered Oct 12 '22 19:10

Schoening