programing

형식 스크립트가 포함된 Vuex 4를 사용하는 유형 'ComponentPublicInstance'에 속성 '$store'가 없습니다.

yoursource 2022. 8. 13. 12:37
반응형

형식 스크립트가 포함된 Vuex 4를 사용하는 유형 'ComponentPublicInstance'에 속성 '$store'가 없습니다.

vuex에서 타이프스크립트 및 vue를 사용하는 프로젝트가 있는데 VSCode에서 다음 오류가 발생했습니다.

Property '$store' does not exist on type 'ComponentPublicInstance<{}, {}, {}, { errors(): any; }, { eliminarError(error: string): void; }, EmitsOptions, {}, {}, false, ComponentOptionsBase<{}, {}, {}, { errors(): any; }, { eliminarError(error: string): void; }, ... 4 more ..., {}>>'

매뉴얼을 읽었더니 다음 내용으로 d.ts 파일을 추가해야 한다고 되어 있습니다.

// vuex.d.ts
import { ComponentCustomProperties } from 'vue'
import { Store } from 'vuex'

declare module '@vue/runtime-core' {
  // declare your own store states
  interface State {
    count: number
  }

  // provide typings for `this.$store`
  interface ComponentCustomProperties {
    $store: Store<State>
  }
}

하지만 VSCode는'ComponentCustomProperties' is defined but never used그리고 내가 말한 첫 번째 에러가 아직 표시된다.

어떻게 하면 이 문제를 해결할 수 있을까요?

VSCode에서도 이 오류가 발생하여 해결되었습니다.

// vuex.d.ts
import { ComponentCustomProperties } from 'vue'
import { Store } from 'vuex'

declare module '@vue/runtime-core' {
  // declare your own store states
  interface State {
    count: number
  }

  // provide typings for `this.$store`
  interface ComponentCustomProperties {
    $store: Store<State>
  }
}

공식 문서에 따른 설정은 적용되지 않았습니다.VSCode를 재시작한 후, 드디어 적용되었습니다.

더하다/* eslint-disable */shims-vuex.d.ts 파일의 맨 위로 이동

언급URL : https://stackoverflow.com/questions/65237129/property-store-does-not-exist-on-type-componentpublicinstance-using-vuex-4

반응형