Prop type inference for typeof Symbol()
is incorrect and breaks Vue runtime checks
#12234
Labels
typeof Symbol()
is incorrect and breaks Vue runtime checks
#12234
Vue version
3.5.12
Link to minimal reproduction
https://play.vuejs.org/#eNp9UsluwjAQ/RXLJyqhoJb2AoGqC4dWaosKR0uVCRMIdWzLdlhE8+8dO5Ag1HKyZ96bmTfLnj5oHa0LoD0a28Rk2hELrtBDJrNcK+PIk8o1SY3KCaNRx1uez2ifybhThSAZDQe5FtwBWoTEIayD/7hTA7RNnU2UTLNFtLJKYtG9JzOaIDsTYD60y5S0jPZIQDzGhVCb1+BzpoD20Z8sIfn+w7+yW+9jdGzAglmj1hpz3CzAVfBo8g5b/NdgruaFQPYF8BOsEoXXWNEeCzlH2Se8oPYljC6Ti6kdbR1Ie2zKC/XMMvAZxUn6Qf3XeiO3G92GOCZLnOJxC+dbI4LLxQDjME2zwT152012+UyJNqne6U4DKZut8rBOJjeZWz5DygvhbGsOaSZhbJS2cVC05qKA+95pjh8yU0oAlxheDltXbSwWaL26JimvLp+KATkHY88vhUfOYn+wDT3g1VjX5BwcRLR87gPFeUEn2gbBo9I6qo9Zv9ZYCueMmbvRXXR9Q8tfnZgErg==
Steps to reproduce
a.ts
Comp.vue
with<script setup lang="ts">
import and use the symbol as prop type and default:boolean
.==> Check the JS output, and you can see that only the
boolean
type of the type union is inferred:Prod
modeDEV
mode.==> Now you will get the error:
can't convert symbol to string
Why is the DEV mode switching relevant?
We are building a component library and there we use symbols as explicit defaults for special default behaviors.
This issue was only encountered when a user tried to develop (in dev mode) using the compiled lib (in prod mode).
See also: SchwarzIT/onyx#1980 (comment)
What is expected?
or
What is actually happening?
Vue's compiler inferred the prop type used for runtime validation as
Boolean
, even though the typescript type istypeof unique symbol | boolean
. This causes the runtime validation to fail and trying to log an error. Because Vue tries to create an error message using implicit string conversions and symbols cannot be implicitly converted to a string, the JS runtime throws:Uncaught (in promise) TypeError: can't convert symbol to string
System Info
Any additional comments?
We try to use symbols as explicit defaults in place of
undefined
, because the implicit default forboolean
isfalse
.You can find playground examples with different usages of unique symbols here:
https://play.vuejs.org/#__PROD__eNp9Ul1LwzAU/SuXPCmMil8vc06c+KA4J24gQkBqezuraRKSdHbM/Xdv0nbWKXtqcs+5t+eenBW71DpalMj6bGATk2sHFl2pQcRyfs6Zs5wNucwLrYyDFUyfx6PJXQ+my+JViQejdHuemJFSAmPZgycTa40G1pAZVQBn0YEmJo0645LLFLNcou+1gxWXAPV0TGdLjZOsHnfR7/yD2gCUFMsthqOryhpRgVTkVTtnG4cveK0VBmb70/Gvjq1dAvMzrJMS2iw2aOYMCV4P9/bpMzio3SOv6OKw0CJ2SDcAg7SxsZ7TqbMeeZsomeXz6N0qSQ8QvOAsUYXOBZqJdrmSZFofAuKxWAj1eRtqzpTYa+vJGyYf/9TfbeVrnD0YtGgWyNkGc7GZo6vh6+k9VnTegIVKS0HsHeAjWiVKr7GmjUqZkuwOL6i9CT7ncj6z15VDadulvFDPXAc+Z5TCqx2r/8g9jk5CH5lPLoZkRc6SgViFlJKr1rWPft486R5n42V95My/WEP2EekkjfjbofpL3MRjMz20dvPVbWpTMxsSf/aLRvpfFhQO2pb0H0en0eERW38DPKE6Rw==
The text was updated successfully, but these errors were encountered: