guyskk / hami-vuex

🍈 Hami melon flavored Vuex, modular by design, completely TypeScript intelligence, state management for Vue.js.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getter 的返回值推断有问题

zcf0508 opened this issue · comments

commented
export const counterStore = hamiVuex.store({
  // 设置一个唯一名称,方便调试程序和显示错误信息
  $name: "counter",

  // 定义状态
  $state() {
    return { 
      test: {
        a: 1,
      },
    };
  },
  // ↓↓↓  这里 testA 的返回值推断是 any 而不是 number
  get testA() {
    // 这里 this.test.a 的类型能正常推断为 number
    return this.test.a;
  },
});

如上面代码所示,getter 的返回值不能正常自动推断,需要手动指定返回值的类型。

查找到一个相关issue microsoft/TypeScript#49511 ,不知道能不能解决问题。

commented
commented

我看了类型定义的,感觉没什么问题。所以不是很清楚问题出在哪里