vuejs / core

🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
https://vuejs.org/
MIT License
47.81k stars 8.35k forks source link

`ComponentInstance` doesn't work on a generic component with `defineSlots` #12210

Open andreww2012 opened 1 month ago

andreww2012 commented 1 month ago

Vue version

3.5.12

Link to minimal reproduction

https://play.vuejs.org/#eNqFUk1v1DAQ/SsjCym7UpUVrLiEbCSKKiiHUrG9YYTSZDa4OGPLdsJWq/x3xg5dqn5xSTzz3thv3sxBvLc2HwcUhSh945QN4DEMFnRN3UaK4KWoJKneGhfgAOHWInwwHBJSOCcfamoQJtg500PGN2VH9kckdKo5sv9y8tVDIArI3kmSlK5/CF86Yz1sHj9bRrrZPSoofXCKuqr6lr2ysTj7Hi8vV3OH3A8HAXur64AcAZStGqtyFb+Rdw8TJ+xBY2inuvzGG2KjDrFCioafUxrdFxuUIfapgIRErNba/P6ccsENeHKXb35i8+uJ/I3fx5wUlw49uhGlOGKhdh2GGT7bXuCez0ewN+2gmf0C+BW90UPUONNOB2pZ9j1eUnuehsa2XfmzfUDyd01FoZE5Jb4UPKzo9HOt/5O7ztepTtLELj419Je2Drq5gMOrtIMt7hRhWoZFeq0uYJsGnYRdF3Ax9NfoUtQUcGqMxpo4nJZx4nP9Vpvgy7mebmNUwGIJmwpGo1pewqlaLPn3v2X5hGzacxvzY0QX/eP+1vnb/PUbMf0BPTYrPw==

Steps to reproduce

It's not possible to obtain a generic component type using built-in InstanceType helper. So ComponentInstance Vue helper must be used. However, it returns never if a passed component has generic parameter(s) and uses defineSlots with at least 1 slot defined (with any type).

In the reproduction, completely remove defineSlots or remove all slots definitions (leaving only defineSlots<{}>() and the issue will go away.

What is expected?

It returns the component type.

What is actually happening?

It returns never.

System Info

No response

Any additional comments?

No response

jh-leong commented 1 month ago

You can use the vue-component-type-helpers library to extract generic component types, including props, slots, emits, and exposed values. Here's a Playground to try it out.