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

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

Open
dabernathy89 opened this issue Nov 11, 2024 · 1 comment

Comments

@dabernathy89
Copy link

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

  • Define an optional prop with a function type
  • Turn on strict mode in tsconfig

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

@edison1105 edison1105 added scope: types language-tools related to vue language-tools labels Nov 12, 2024
@KazariEX
Copy link
Contributor

image

@edison1105 edison1105 removed the language-tools related to vue language-tools label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants