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

defineModel coerces string to boolean in production build when string | boolean union is used #10676

Closed
zigomir opened this issue Apr 10, 2024 · 3 comments

Comments

@zigomir
Copy link

zigomir commented Apr 10, 2024

Vue version

3.4.21

Link to minimal reproduction

https://play.vuejs.org/#eNqFkslu3DAMhl+F1cUJMLbR5TRwBuiSQwu0CdKiJwG1Y9MTpbKkanGncP3uoWzPZBBkuVH8uXwiObD3xmR9QLZmhautMB4c+mBAVmp7xpl3nG24Ep3R1sMAFlsYobW6g4TSkoP0UXdm8Wd5fMSqJHNVa+U89HAWk0+S5BTyHJy3Qm2jh6sinztTH3p47IysPNILoJjK9mmnG5SE03MGOSlFfhTGVoRJXVqxzW6dVvSXISZzVlO2kGgvjBdEwdkaJiVqlZT675fJ523A1d5f32D9+xH/rdtFH2eXFh3aHjk7aL6yW/SzfP79G+7IPojEHiRFPyNeodMyRMY57ENQDWEfxU20n6dR09x+uPOdR+X2n4qgMXKc4mlMAePgnvr6Pe7b7N2Ux9VIU9yv7YVjWBZayYC01AZbofBrXFCxbPU/XGstsVKbk3gxf4Kw2MyUMJ4+v/BG9JNB5qs0hdkESJd+PljlQCivoYz1SrKhvLy6+FRCPJL7eIudphzQLZQHoHI+0fIIukwc+H8GV9CKHZJ9g2CsvpbYzcXSdAH6GQnWUBiLm2FYgMaxyKNjgs9n+ofX+atHG3dFc6WBZ29es/EO0+omHA==

Steps to reproduce

Make sure to first click on Comp.vue tab to render it first (dunno why this is needed, but it is).
Click on Dev to flip it to Prod in the top nav and see Value: turns to Value: true.

What is expected?

Dev and prod mode should work the same, keeping model value a string.

In other words, type annotation shouldn't coerce model's value.

What is actually happening?

Model turns to boolean in prod mode.

System Info

No response

Any additional comments?

Sorry if this has been reported, I couldn't easily find an issue if it was.

@sqal
Copy link
Contributor

sqal commented Apr 10, 2024

#9603

@Shyam-Chen
Copy link
Contributor

Shyam-Chen commented Apr 11, 2024

https://vuejs.org/guide/components/props.html#boolean-casting

const value = defineModel<boolean | string>({ required: true });

@zigomir
Copy link
Author

zigomir commented Apr 11, 2024

https://vuejs.org/guide/components/props.html#boolean-casting

const value = defineModel<boolean | string>({ required: true });

Thanks!

I now see that if I change order from <string | boolean> to <boolean | string> then both prod and dev work the same, which is definitely better. Although I still think that my reported case should work the same in dev as in prod.

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

No branches or pull requests

4 participants