vuejs / core

🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
https://vuejs.org/
MIT License
47.8k stars 8.35k forks source link

Optional function prop not optional in SFC template tag when TypeScript strict mode is enabled #12361

Open dabernathy89 opened 2 weeks ago

dabernathy89 commented 2 weeks ago

Vue version

3.5.12

Link to minimal reproduction

https://play.vuejs.org/#eNp9U12P2jAQ/CvbPIFEE9GqLxQ4VZxQqXpt1T42bWWShfjOsS2vE0An/ns39iG4Izok8rE7Gc+M14/JJ2vTtsFkkkypcNJ6IPSNBSX0dpYnnvJknmt/sAg/nLEEM3jMNUB9WDa6uJnAYAizOZB3Um8/5vrI/8Jo8mCf4Dvpq1vciEZ5GpS4kRoD0zRc54Ph6JJxAo2OoHLEbEOmOxFGwNKZ+qQkLJHGOgNfALiSZQB/b3I9zaI5tsIvHmurhEd+A5hW4+4G0L6VG3YcSfKkKwYAwGezKw9vAjirxlycZhcUyYhTYoUbuU3vyWiOMvgByJPC1FYqdN+tl+whTybRa/xxvMJt0XflPEHSuOdntn0G1KZsFL4CuKd97FqHhK5l7LN+tzFFWMG7Bnu4fyIZ1XTyIo825UsO3Ft0skbthbrFwjjhjQtmrjjpQdqvcr2osHjoBSDdhWVX2iNvUi9GKGV2vw7aV+hl8TQ7q9oa141jzwcb4wpccMCSPKtcCOJhXOklR/9N1Nj/UUPI1DxoS+MWShAtJaqyH8vZGtXiF97eKL/fvGlYx53od6Xkuqv/PtdOiVxta2yUpu6vppKzE+tOxVU7znlliBnPvT/PlHSnOfi80tIyc1YoySH2cHdd8tlWmbVQTHDBHx+PfGLDgfjXoiMeKT4L79MP6fhdcvwPqWZcNQ==

Steps to reproduce

What is expected?

The prop should retain undefined as part of its type definition in both the script and template blocks of a SFC.

What is actually happening?

While the type is correct in the script block, it is not optional in the template block.

This causes a TypeScript error when you try to check if the prop is defined in the template, because TypeScript thinks that the function will never be falsy:

This condition will always return true since this function is always defined. Did you mean to call it instead? ts-plugin(2774)

System Info

No response

Any additional comments?

No response

KazariEX commented 2 weeks ago

image