vuejs / core

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

`defineProps` cannot declared generic boolean type #9877

Open alexzhang1030 opened 11 months ago

alexzhang1030 commented 11 months ago

Vue version

3.3.4

Link to minimal reproduction

https://play.vuejs.org/#eNp9UVFLwzAQ/itnXjphrsjeSjdQGagwHSr4kpfaXrvMNAlJOgel/91LxmYfZE/hvu+7y/fd9ezOmNm+Q5ax3JVWGA8OfWdAFqpZcOYdZ9CgQitKKteAB4+qcvCltcRCcbbkSrRGWw89WKxhgNrqFhIamnDFVYW1ULix2ri85wqgzWAd3iI7D1HDcnIdxKVWzkPrGliEYZPkEaXU8KmtrK4SkuTp0SX9SoXH1sjCI1UA+fZ22fexeRjylKqICmU6D/ubVlcoKQLxFCklMk9H/WxKWen7WjSzndOKFhLdclbq1giJ9tV4QfY4yyAygSvI3c9zxLztcHrCyy2W3//gO3cIGGcbiw7tHjk7c76wDfojvXp/oUWPSHLfSVJfIN/QadkFj0fZfacqsj3SRbdP8VhCNR9uFW7pTqGC0aAcop4zOuDDheh/duezeeyjM7LhF5jJxRc=

Steps to reproduce

See vue playground, the compiled prop result

What is expected?

the compiled prop m should be { type: Boolean }

What is actually happening?

the compiled prop m is {}

System Info

No response

Any additional comments?

No response

so1ve commented 11 months ago

The compiler doesn't resolve generics declared in <script setup generic="...">.

alexzhang1030 commented 11 months ago

Should it be supported in the future, or it be designed thus?

so1ve commented 11 months ago

You can try https://github.com/so1ve/vue.ts/tree/main/packages/complex-types.

ascott18 commented 1 week ago

Declaring the prop as TGeneric & boolean instead of just TGeneric seems to work for me, without breaking the generic-ness of the prop.

defineProps<{
  multiple?: TMultiple & boolean;
>);