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

defineProps with a TS type and optional boolean has inconsistent behavior #5034

Open
KazariEX opened this issue Dec 8, 2024 Discussed in #5030 · 0 comments · May be fixed by vuejs/core#12509
Open

defineProps with a TS type and optional boolean has inconsistent behavior #5034

KazariEX opened this issue Dec 8, 2024 Discussed in #5030 · 0 comments · May be fixed by vuejs/core#12509

Comments

@KazariEX
Copy link
Collaborator

KazariEX commented Dec 8, 2024

Discussed in #5030

Originally posted by TheDutchCoder December 7, 2024
We use TS to define props this way:

const props = defineProps<{
  foo?: boolean
}>()

This all works, but Vue compiles optional booleans as false, not as undefined.
What's interesting is that in the template this works if you access props.foo, but not foo:

<template>
  <!-- Throws error as foo can be undefined -->
  <SomeComponent :is-visible="foo" />
</template>

<template>
  <!-- This works as expected -->
  <SomeComponent :is-visible="props.foo" />
</template>

Our question is: is this a Vue bug, or a language tools bug?

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

Successfully merging a pull request may close this issue.

1 participant