Closed RayGuo-ergou closed 1 month ago
2.1.6
none
3.5.12
5.6.2
No response
interface Props { amount?: number; } const { amount = '1'} = defineProps<Props>();
When assigning string to number it should type mismatch error.
It accepts the wrong type value and then infers the type of amount to number|"1"|undefined
amount
number|"1"|undefined
https://play.vuejs.org/#eNp9UstOwzAQ/JXFl4AEjRCcSloECAk4AAIkLr6EZBMMjm35USpF+XfWTmkLQr1Y9s7seOydnl0YM1kEZFNWuMoK48GhD2bOleiMth56sNjAAI3VHWREzdbQDUqpX7WV9Qqd5JtSVM3OuOKq0sp56FwLs6i1nyUSJNZedsBVkY9X06V08NgZWXqkE0Dxfjzv+9Q8DEVOp1QVygQPi6NO1yhnnBHOGeQjuPEwL7YMEVjkW+LskHlH3hrRTj6cVvQFfeznrNKdERLtg/GCvHM2hYRErCS5r7tU8zbg4U+9esfq85/6h1vGGmePFh3aBXK2xnxpW/QjfP18j0var0F6WpDE3gE+odMyRI8j7TKommxv8ZLb2zQtodoXd730qNzPo6LRyBwSnzOa2NWOp2/snkxOUx9XA/3i75n/TRLIUrU0Ik9iMVXKo23KCuHRauNG9bLTQfnzKajQvaGl1JD0GJt+BVJ2suOMcjiDGhuhMLUXaZ3vH6Sg7cpRLRZpA0BxWkkOdAtB+Yj9DsfwDRL6DAM=
It seems will not render tho, but no typescript error.
I think it's a limitation of TS.
Right forgot it's type casting.
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
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
tonumber|"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.