How to Fix Vuex TypeScript Errors in a Vue Project

TypeScript declaration example for Vuex

Fix missing Vuex type declarations in a TypeScript project by adding a module declaration file.

9th June 2024

2 min read

Introduction

In some Vue and TypeScript projects, the editor may report that Vuex types cannot be found. If your installed Vuex version exposes the declaration files shown below, a local module declaration can help TypeScript resolve them.

Add a declaration file

  1. Create a vuex.d.ts file in your project root (or another directory included by tsconfig.json).
  2. Add the following declarations:
declare module 'vuex' {
  export * from 'vuex/types/index.d.ts'
  export * from 'vuex/types/helpers.d.ts'
  export * from 'vuex/types/logger.d.ts'
  export * from 'vuex/types/vue.d.ts'
}
  1. Restart the TypeScript server or development server so it picks up the new declaration.

If the error remains, check that the paths exist in your installed Vuex version and that the declaration file is included by your TypeScript configuration. Package declaration layouts can differ between versions.