Subscribe on changes!

type of reactive collection values is abnormal

avatar
Aug 3rd 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

avatar
Aug 7th 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

avatar
Aug 7th 2023

@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