Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getter 的返回值推断有问题 #3

Open
zcf0508 opened this issue Mar 23, 2023 · 2 comments
Open

getter 的返回值推断有问题 #3

zcf0508 opened this issue Mar 23, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@zcf0508
Copy link

zcf0508 commented Mar 23, 2023

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 ,不知道能不能解决问题。

@guyskk guyskk added the bug Something isn't working label Mar 25, 2023
@guyskk
Copy link
Owner

guyskk commented Mar 25, 2023

可以复现,这个是类型定义 https://github.com/guyskk/hami-vuex/blob/main/src/index.d.ts

@zcf0508
Copy link
Author

zcf0508 commented Mar 25, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants