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

fix: hooks missing return type #1200

Closed
wants to merge 2 commits into from
Closed

fix: hooks missing return type #1200

wants to merge 2 commits into from

Conversation

gin-lsl
Copy link
Collaborator

@gin-lsl gin-lsl commented Oct 8, 2024

fix #1175

💡 Background and solution

修复 useAccountuseConnection 返回类型丢失问题

🔗 Related issue link

Copy link

changeset-bot bot commented Oct 8, 2024

🦋 Changeset detected

Latest commit: f20ab4d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@ant-design/web3 Patch
@example/eth-web3js Patch
@example/ethers-v5 Patch
@example/ethers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Oct 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ant-design-web3 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 10, 2024 11:19am

Copy link

github-actions bot commented Oct 8, 2024

Preview is ready

Copy link

codecov bot commented Oct 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.99%. Comparing base (08c5321) to head (f20ab4d).
Report is 24 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1200   +/-   ##
=======================================
  Coverage   99.99%   99.99%           
=======================================
  Files         851      851           
  Lines       18149    18149           
  Branches     1582     1582           
=======================================
  Hits        18148    18148           
  Misses          1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

import useProvider from './useProvider';

export default function useAccount() {
const { account } = useProvider();
const { account } = useProvider() as UniversalWeb3ProviderInterface;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

好奇怪,为啥我这里看是有类型的。

另外感觉用 as 不太好,有问题的话最好也是通过补充 useProvider 的类型来解决。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

我看项目里面的 demo 这个类型是有的

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要看打包后的 d.ts 文件,不用 as 指定一下类型,会导致编译结果不对:
image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不有应该啊,总感觉有其它更好的办法,as 一般是用在那种本来就有可能有多种类型的情况下用来指定类型。但是这个的问题是类型没有推理出来,最好再研究一下

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

又改了一下,原因似乎是由于把 enum 和 type/interface 放到同一个文件里面了。导致后面的模块寻找类型的时候出错了。

我在本地试了下可以了,你那边最好也拉下来试一下。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥 enum 和 type 放一起会有问题?可以研究下两种情况下构建出来的 type 文件有什么区别。

感觉这种问题一般是 ts 构建 .d.ts 文件的时候把一些类型吞掉了。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

检查了下,编译出来的类型并没有丢失。

而且毕竟,这个文件中的类型很多地方都有用,如果丢失了,那么其他用到的地方应该都有问题,而事实是只发现这两个 hook 里面的类型有问题。

能想到的其他原因,例如“循环依赖”、“TS 编译时类型查找错误”,似乎都不能满足上面这一点。。。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

奇怪,那为啥分开写到一个单独的文件就好了

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种修复方式似乎是不对的,我今天再次执行 build 后,又出现了原问题。

@@ -1,3 +1,4 @@
export * from './enums';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉 enums 算是 types 中的一种,应该在 types 中导出 enums。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] useAccount can not find type
2 participants