【发布时间】:2021-03-22 00:42:46
【问题描述】:
我有一个项目,我在 vuex 中使用 typescript 和 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 ..., {}>>'
我阅读了the documentation,它说我必须添加一个包含此内容的 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 抱怨,它仍然显示我提到的第一个错误
我该如何解决这个问题?
【问题讨论】:
标签: typescript vue.js visual-studio-code vuex