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

在模板(<template>)内使用函数型的属性(attribute)中, ref的value 无法被TypeScript正确的检查 #4604

Closed
amulet-faith opened this issue Jul 22, 2024 · 0 comments · Fixed by #4609
Labels
bug Something isn't working

Comments

@amulet-faith
Copy link

Vue - Official extension or vue-tsc version

v2.0.26

VSCode version

1.91.1 (Universal)

Vue version

3.4.33

TypeScript version

5.4.0

System Info

Browser: Chrome Version 126.0.6478.183 (Official Build) (arm64)
System: MacOS Sonoma 14.5

Steps to reproduce

创建允许传入回调函数作为Prop的子组件
创建调用它的父组件, 并直接在模板内传入函数实现, 在函数实现内使用Ref定义的变量

What is expected?

运行和TypeScript检查保持一致

What is actually happening?

如图, 如果没有.value 则可以正确运行, 但是TS检查报错:
Property 'choosedFormIdList' does not exist on type 'Ref<{ curTaskId?: number; choosedFormIdList?: (string | number)[]; }>'.ts(2339)

image

浏览器的 console 可以得到预期结果:

no_value_runtime_no_error



然而 如果加入 .value 则TS可以正确检查代码, 但是运行时报错:

code_no_error

浏览器的 console 报错如下:
TypeError: Cannot set properties of undefined (setting 'choosedFormIdList')

runtime_error

Link to minimal reproduction

No response

Any additional comments?

No response

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

Successfully merging a pull request may close this issue.

2 participants