Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

withDefaults doesn't respect type definition of defineProps - able to add unknown property. #9899

Closed
rasmus0201 opened this issue Dec 22, 2023 · 0 comments · Fixed by #9998
Closed

Comments

@rasmus0201
Copy link

Vue version

3.3.4

Link to minimal reproduction

https://play.vuejs.org/#eNp9U01v2zAM/SucMMAJ4LiH3jy33VeAFdi6Yit20kWx6USdLAmWlKQI8t9HSXHaYkAvtsRHPz4+0gf2ydpqG5DVrHHtKK0Hhz5YUEKvrzjzjrNrrqX2OPaiRbgfjXVw4BpgMB2qP0IFvKlhZYxCoT9EoJNOrBR2r8JHrrlujXYebOK4gp30m6/Yi6C8m3XYS42JvknP69m8zIW2sUYNvVAOy5cFTjEin1OFiR4H6Yk9Ey7p4ppEM8Mtal8DZ8F2wmP93ABn5VTlpHhew9bILgonIfRqLrI/5AZdPA5WEQfdABqpbfDxBOCfLJJv7Qbbvyuz5yyH6xTAjqDUfZWqndGpoTM8BaaMj+2GBhKZY3ez4r8OihJm71ODlRfjGj0IB98efny/jdqWCgeC5tVJxjzzXiT5h0OeSNYEN1A8oSughkKbAo5HaN4tFnCHu5QGK2xFcAimfzXAElbBw4aqRgvIZE1qRs5gsbiGaN/ZMlbSWtGoermuHp3RtHtpPuSaGaxUOP60XtIoOavzAkTM+VG2Pob8GPIaxPCjI4/jTO9HdDhu4ygnLBuR4eXvO9zT+QySdUFR9hvgL3RGhSglp30OuiN1L/KEUmZ3O1gzeqnXD26596jdpD0KjZnHlM8Z/Wdf3ujwWe5ldZm+o+Vjx38lvTqz

Steps to reproduce

  1. Notice how the withDefaults incorrectly assigned value: "" as the default modelValue.
  2. Observe that TypeScript doesn't complain about adding an unknown property to withDefaults
  3. Observe in the template that props.value is used (and compilation is alright) - but notice the value doesn't change if you toggle the checkbox.
  4. Using value (ie. removing props.) in the template will make a compilation error because it now uses the definition of defineProps instead of the generated on that withDefaults makes for the props object.

What is expected?

Compile error when defining a default value in withDefaults for a property that doesn't exists on the interface / defineProps().

What is actually happening?

The value property gets added to the props object with type never.

System Info

No response

Any additional comments?

Ran into this issue in a production app where the modelValue should have had a default value, which incorrectly got set to value: "" - a bit unfortunate that it ended up in production and the state of the checkbox weren't visible. This could have been mitigated if we were warned by typescript that we are trying to add a property that doesn't exist in the Props / on the component

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants