vuejs / language-tools

⚡ High-performance Vue language tooling based-on Volar.js
https://marketplace.visualstudio.com/items?itemName=Vue.volar
MIT License
5.87k stars 403 forks source link

[Type/vue3.5]: Destructure prop allow assign wrong types #4929

Closed RayGuo-ergou closed 1 month ago

RayGuo-ergou commented 1 month ago

Vue - Official extension or vue-tsc version

2.1.6

VSCode version

none

Vue version

3.5.12

TypeScript version

5.6.2

System Info

No response

package.json dependencies

No response

Steps to reproduce

interface Props {
  amount?: number;
}
const { amount = '1'} = defineProps<Props>();

What is expected?

When assigning string to number it should type mismatch error.

What is actually happening?

It accepts the wrong type value and then infers the type of amount to number|"1"|undefined

Link to minimal reproduction

https://play.vuejs.org/#eNp9UstOwzAQ/JXFl4AEjRCcSloECAk4AAIkLr6EZBMMjm35USpF+XfWTmkLQr1Y9s7seOydnl0YM1kEZFNWuMoK48GhD2bOleiMth56sNjAAI3VHWREzdbQDUqpX7WV9Qqd5JtSVM3OuOKq0sp56FwLs6i1nyUSJNZedsBVkY9X06V08NgZWXqkE0Dxfjzv+9Q8DEVOp1QVygQPi6NO1yhnnBHOGeQjuPEwL7YMEVjkW+LskHlH3hrRTj6cVvQFfeznrNKdERLtg/GCvHM2hYRErCS5r7tU8zbg4U+9esfq85/6h1vGGmePFh3aBXK2xnxpW/QjfP18j0var0F6WpDE3gE+odMyRI8j7TKommxv8ZLb2zQtodoXd730qNzPo6LRyBwSnzOa2NWOp2/snkxOUx9XA/3i75n/TRLIUrU0Ik9iMVXKo23KCuHRauNG9bLTQfnzKajQvaGl1JD0GJt+BVJ2suOMcjiDGhuhMLUXaZ3vH6Sg7cpRLRZpA0BxWkkOdAtB+Yj9DsfwDRL6DAM=

Any additional comments?

It seems will not render tho, but no typescript error.

KazariEX commented 1 month ago

I think it's a limitation of TS.

image

RayGuo-ergou commented 1 month ago

Right forgot it's type casting.