vuejs / core

đź–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

Home Page:https://vuejs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generic prop type resolves to non-generic type with runtime `defineProps` declaration

YaredFall opened this issue · comments

Vue version

3.4.31

Link to minimal reproduction

https://play.vuejs.org/#eNq1U01v1DAQ/Ssjc2iRVolQOYUQBKgHONBqm6MllCazwVvHtvyRLlrtf2fssNl0BT21p9gzzzPvzbzs2WdjsjEgK1jpWiuMB4c+mIorMRhtPayD8mLAr3owsLF6AM6yfBGMrzmb4fXdU+R0P4LKfGpC5enicTCy8Ug3gHLZqBgbGfAjZ3vYaF3AxX1jLw6cVfMbeNPhpgnSJ1CCQwLkc9VySTP1SH3+MnyhFlM1qr6IcsVWzLtWq43os63Tisa7TwRYS2gh0d4YL7RynBWQMjHXSKkfv6eYtwFXx3j7C9uHf8S3bhdjnN1adGhHGvGc843t0U/p67sfuKPznBx0FyShn0mu0WkZIscJ9iWojmgvcIntt7R1ofraXe88KncUFYlG5CHhOSMDxEH9T/qJ7lX2Pr3j6kBTPDPauU1BNqqn9XiqBj0qtKKlaw0kCVXnYI2ttl3pvCWOKwjqQelHVdEWZ8fu4dZqU/82tN2jb5NdP0STkgWEwohwl4lt8sHM3NOzAm7ut9h6aNxcqqyrJDzKePu87zsxpgMdndT+ZMz0JV35hMsn4LnPTj/Yiw7nifLypPxTATVpqi5fV9XPEW30EmkiQ2RX79jhD1EllMo=

Steps to reproduce

Look at the RuntimeComp.vue and TSComp.vue compoents.
They have same generic prop value with type T extends Record<string, unknown>, but RuntimeComp uses runtime props declaration, while TSComp uses type declaration.
Now look at the App.vue component. When you hover over value prop, you can see that types are not the same.
TSComp.vue properly inherits generic type ({ foo: 'bar'} in the example) while RuntimeComp.vue resolves type to Record<string, unknown>, thus losing generic type

What is expected?

Both RuntimeComp.vue and TSComp.vue should resolve generic type to the same type ({ foo: 'bar'} in the example) and should not lose generic type

What is actually happening?

RuntimeComp.vue resolves to non-generic type (Record<string, unknown> in the example)

System Info

No response

Any additional comments?

No response

Generics are only supported when using the type interface declaration

Hi @LinusBorg!
Would you care to explain why there is such a limilation and if there are plans to support all cases?
I always use the object syntax for defineProps and up until recently(maybe a month or two prior) I was able to use generics this way.
Somewhere down the road it stopped working and started inferring them as unknown.
Thanks for your time!