greenpress / vuex-composition-helpers

A util package to use Vuex with Composition API easily.
https://www.npmjs.com/package/vuex-composition-helpers
MIT License
290 stars 32 forks source link

Property '$store' does not exist on type 'ComponentInternalInstance | CombinedVueInstance<Vue, object, object, object, Record<never, any>>' #64

Open rafaelmagalhaes opened 2 years ago

rafaelmagalhaes commented 2 years ago

Recently my test started failing with this error

  node_modules/vuex-composition-helpers/src/util.ts:104:9 - error TS2339: Property '$store' does not exist on type 'ComponentInternalInstance | CombinedVueInstance<Vue, object, object, object, Record<never, any>>'.

    104  const {$store} = 'proxy' in vm ? vm.proxy : vm;

I'm using this package version 1.1.0 with nuxtjs and nuxt-composition package

Node version: 14.17.5 NPM version: 6.14.15

Here's my jest config file

module.exports = {
  moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/$1',
    '^~/(.*)$': '<rootDir>/$1',
    '^vue$': 'vue/dist/vue.common.js',
  },
  moduleFileExtensions: ['ts', 'js', 'vue', 'json', 'jsx', 'json'],
  transform: {
    '^.+\\.(ts|tsx)?$': 'ts-jest',
    '^.+\\.(js|jsx)$': 'babel-jest',
    '.*\\.(vue)$': 'vue-jest',
    '^.+\\.ts?$': 'ts-jest',
  },
  testMatch: ['<rootDir>/**/*.spec.js', '<rootDir>/**/*.spec.ts'],
  collectCoverageFrom: ['<rootDir>/components/**/*.vue', '<rootDir>/pages/**/*.vue', '**/*/*.ts'],
  coveragePathIgnorePatterns: ['/node_modules/', '/types/', '/proto/', '/.nuxt/'],
  setupFilesAfterEnv: ['./jest.setup.ts'],
  snapshotSerializers: ['jest-serializer-vue'],
  transformIgnorePatterns: ['<rootDir>/node_modules/(?!vuex-composition-helpers)'],
};
davidmeirlevy commented 2 years ago

Can you try to locate where is the $store located in this version of nuxt?

rafaelmagalhaes commented 2 years ago

Can you try to locate where is the $store located in this version of nuxt?

image

rafaelmagalhaes commented 2 years ago

manage to solved it by doing this


// vuex-shims.d.ts

import { Store } from 'vuex';

declare module '@vue/composition-api' {
  interface ComponentInternalInstance {
    $store: Store<any>;
  }