属性 使用 Typescript 的类型 'Computed' 上不存在 XXX

Property XXX does not exit on type 'Computed' using Typescript

代码运行并在浏览器的控制台中打印出 true。但是在我的本地服务器上出现错误 Property 'authorities' does not exist on type 'Computed'. 我是 Typescript 和 Vuex 的新手。我检查了一下,isAdmin 是一个具有权限的对象,它是一个数组

这是我的代码

export default {
    name: "UserSettingsTabs",
      computed: {
    ...mapGetters({
      preferences: 'tab/preferences',
      administrations: 'tab/administrations',
      isAdmin: 'auth/currentUser'
    }),
    isUserAdmin() : boolean{
      console.log(this.isAdmin.authorities.includes('Admin'));
      return this.isAdmin.authorities.includes('Admin');
    }   }, }

这是因为您使用的 mapGettersisAdmin 解析为 <Computed>

对此进行了讨论here,并提供了一些可能的解决方案

如果您接受简单的解决方案,则可以将 this.isAdmin as IIsAdmin 与您的自定义界面或类型结合使用。

您也可以使用从 vuex 中提取值的计算而不是使用 mapGetters。