Skip to content

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

@KazariEX

Description

@KazariEX

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions