Subscribe on changes!

When props use generics and are simultaneously used with withDefaults, toRefs cannot correctly infer their types

avatar
Dec 7th 2023

Vue version

3.3.10

Link to minimal reproduction

https://play.vuejs.org/#eNp9Uk1PwzAM/StWLgxprELcSjfElxAcAMGOuVStWwJtEiXumDT1v+MkbAwE3BL7+fnZfhtxbu1sNaDIReErpyyBRxosdKVu51KQlwJa1OhUxd+lFAupVW+NI9gAmSdsPIzQONODFEwkxekOcI+esL40/NOoaYuaZSkR+kY4F2hC15QVwqMz1hfL4wVspAbofXuWgyendMtI2GoJsByWxxwbA0FltCewoRjm8K7o5QqbcujIT2pslMbE+8m+WEwOp7sGOWuSYspMh1FM4tqEFI82/5xyEskDosjSpngT/CHsbVcS8g+gqNUqPgBuD3q4SWJToPi5jpw4cBRoebPcjDedJZYs0RTZHrmY8jFYWqPa2as3mi8WB5CiYkbVoXuwpFi6FHkaLeTKrjPvdzFGbkAeMsWrF6zefom/+nWISfHo0KNb8YF2OSpdi5TS18/3uOb3LtmbeugY/U/yCb3phqAxwS4GXbPsPVxUexvNw/de+us1ofbboYLQgBwjProtLPOv0b/knsxOYh1fmLf4Zb7/TM8b3zcOe53LkuuSG2FkE/3thnB+HTt9v+L4Ae5pKuU=

Steps to reproduce

  1. Define a prop using generics, and then specify another prop using a non-generic definition.
  2. Use toRefs to resolve the props
  3. Use resolved prop attach to nested component
image image

What is expected?

The type is correct.

What is actually happening?

The type is incorrect.

System Info

System:
    OS: macOS 14.1.2
    CPU: (10) x64 Apple M2 Pro
    Memory: 303.87 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    Yarn: 1.22.21 - ~/Library/pnpm/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
    pnpm: 8.11.0 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 120.0.6099.62
    Safari: 17.1.2
  npmPackages:
    vue: ^3.3.10 => 3.3.10

Any additional comments?

No response

avatar
Dec 18th 2023

I meet the same problem.

  1. the type turns any when using toRefs
  2. the type is incorrect in template

vue:3.3.10

image image image image

avatar
Jan 9th 2024

Also experiencing this exact error, using computed worked for me, toRefs working correctly would be even better though