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

使用泛型hook,ts类型推断错误 / Using generic hook, ts type inference error #4341

Closed
zhengybo opened this issue May 5, 2024 · 5 comments
Labels
question Further information is requested

Comments

@zhengybo
Copy link

zhengybo commented May 5, 2024

测试用例/demo
demo.zip

hooks.ts
image

test.vue
image

如果在函数中使用了抛出的值 / If an thrown value is used in a function
image
这里a会被推断为any / Here, variable a will be inferred as any

将test 函数中的a引用注销,推断恢复 / Unregister the reference to a in the test function and infer recovery
image

尝试去掉泛型,类型推断正常 / Attempting to remove generics, type inference is normal
image
image

例子最终运行结果正常,但是ts推断异常 / The final running result of the example is normal, but ts inference is abnormal

Vue - Official: v2.0.16
VSCode: v1.89.0
系统: Windows 11
框架: vite vue3

@zhengybo zhengybo changed the title 使用泛型hook,ts类型推断错误 使用泛型hook,ts类型推断错误 / Using generic hook, ts type inference error May 5, 2024
@so1ve
Copy link
Member

so1ve commented May 6, 2024

What is AnyObject?

@zhengybo
Copy link
Author

zhengybo commented May 6, 2024

What is AnyObject?
就是
{ [key: string]: any; }

@zhengybo
Copy link
Author

zhengybo commented May 7, 2024

能复现了?

What is AnyObject?

@KermanX
Copy link

KermanX commented May 11, 2024

I think this is not related to the Vue language tools. In plain TypeScript you can also get this error:

image

@johnsoncodehk
Copy link
Member

Closed due to answered in #4341 (comment).

@johnsoncodehk johnsoncodehk added the question Further information is requested label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants