ts、useStorage (vueuse) 和 Pinia 的类型问题

Typ*_*aon 6 local-storage typescript vue.js pinia

我在以下代码中遇到奇怪的错误: Property 'length' does not exist on type '{ [RefSymbol]: true; }'.

但是当我检查 getCount 函数中的类型时,foo我的 IDE 告诉我它的类型Foo[]。我究竟做错了什么?

import { defineStore } from 'pinia';
import { useStorage } from '@vueuse/core';

interface Foo {}

export const useFooStore = defineStore('foo', {
  state: () => ({
    foo: useStorage('foo', [] as Foo[]),
  }),
  actions: {
    getCount() {
      return this.foo.length; //Here's the error
    },
  },
});

Run Code Online (Sandbox Code Playgroud)

rel*_*one 0

现在您的帖子中没有太多信息,但根据错误消息的内容,我猜测以下内容。您正在定义一个具有以下类型的对象

{ [RefSymbol]: true; }
Run Code Online (Sandbox Code Playgroud)

但由于您的类型不存在长度,我认为工作需要一个数组?