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

type of reactive collection values is abnormal #8904

Closed
Teiiiiiio opened this issue Aug 3, 2023 · 4 comments · Fixed by #8960
Closed

type of reactive collection values is abnormal #8904

Teiiiiiio opened this issue Aug 3, 2023 · 4 comments · Fixed by #8960
Labels
has PR A pull request has already been submitted to solve the issue scope: types

Comments

@Teiiiiiio
Copy link

Teiiiiiio commented Aug 3, 2023

Vue version

3.3.4

Link to minimal reproduction

https://play.vuejs.org/#eNqtVMlu2zAQ/ZUJL7YRWUabm+G4S5BDizYJ0gA5hDnQ8shhIpECF2cR9O8dkt4aBEZaVCeR84bz5s0jW/alafKlRzZmE1sY2Tiw6HwDlVCLY86c5WzKlawbbRy0YFAUTi4xM1hm0l6ultBBaXQNPTqqxxVXhVbWwUzrBwvHm6y+wkf4KZr+DVdA303v6g7hh3SuQrgwUhXYy6hKY2SBY0or+x8G0N1mu/BrreZoSl/BtXwRZg66hPMXeJ34cZV4OxgEQqORo9wYB/fcIEgLl1hOznw9QzPNZt6FtLAtvNO1cLIQVfUMXj0a0TQ4z2ZYCG8xdZUv0PXfoD9IB6d+PyUhdIV5pRd9zraK9fefMubs8N3g0OGfdfbj8yQTlXgP7rV8+VJUfiuiigJG/Yisj5oJRbLNsZQK/4VZqvBefgkdWSbXaXVSyeKBfNdXosaxdYRfZKnpRHcAx1Nog6t22QX0IWc9u/KJtIHDWoQuVJiM0i2hO0ELh3VTCYe0ApjM5RKWw1Ibujc34axMqlLfglTJMpzB5yIwo/iKYywZYWut2XRyMByC9UWB1h4EWaPSaIw2MBzGUgBtGzK7bty22+yOKBKPERH5b4zW6q547TqAhr+e8l8Rm4w2urGMXhgaQSkX+b3Vip6hOBXOCl03skJz3jhJI+JsnOYVYuQx/fg97jnjcfU6UM4dFg9v7N/bp7DH2YVBi2aJnG1iThiyVwqf/jrDJ/rfBGs99xWh9wQvkezjA8cE+0qSEO0dXGT7LT6gZMMre/rkUNl1U4FoQHYRzxk9oCd7Wt/SPcqPYh4Zk3W/AZf6+Tk=

Steps to reproduce

1.create reactive map

const books = reactive(new Map([
    ['The Little Prince', { price: ref(1) }],
    ['The Wonderful Wizard of Oz ', { price: ref(2) }],
]))

2.show

  <div v-for="[name,info] in books" @click="onClick(name,info.price)"><!-- success!but type error -->
    {{name}}:{{info.price}}
  </div>

3.add click event to print book's name and price

const onClick = (name:string,price:number) => {
  console.log(name+"'s price is:"+price)
}

What is expected?

info.price type should be number

What is actually happening?

Argument of type 'Ref<number>' is not assignable to parameter of type 'number'

System Info

No response

Any additional comments?

No response

@Teiiiiiio
Copy link
Author

Teiiiiiio commented Aug 7, 2023

@TheDutchCoder Thanks for your reply
When i explicit add reactive for map values,The type is correctly
playground

const books = reactive(new Map([
    ['The Little Prince', reactive({ price: ref(1) })],
    ['The Wonderful Wizard of Oz ', reactive({ price: ref(2) })],
]))

price is already reactive, you probably shouldn't make them refs. Specifically this part seems

In my project,I want to provide a computed for price,It seems I should use watch in your example

@Teiiiiiio
Copy link
Author

@TheDutchCoder sorry,i didn't make myself clear
playground

I think this is just normal behaviour

I think so too,but when i not explicit add reactive,type is unautomatically unwrapped,In fact, it has automatically unwrapped in line 40

sxzz added a commit that referenced this issue Aug 12, 2023
@sxzz sxzz added the has PR A pull request has already been submitted to solve the issue label Aug 12, 2023
sxzz added a commit that referenced this issue Nov 21, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
has PR A pull request has already been submitted to solve the issue scope: types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants