vuejs / vuejs/core

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

Open
#9,765 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

scope: types
Dominant language
TypeScript
Stars
54.4k
Forks
9.2k
Avg merge
1d 5h
Merged PRs (30d)
140

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Vue Play reproduction and inspect the TypeScript typings involved in generic props, withDefaults, and toRefs. Compare the inferred type with the expected nested-component prop type; done means the resolved prop type is inferred correctly without changing the reproduction setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.