Skip to content

prop with default value is still required #5939

@thomasaull

Description

@thomasaull

Vue - Official extension or vue-tsc version

3.2.2

VSCode version

1.104.3

Vue version

3.5.26

TypeScript version

5.9.3

System Info

System:
  OS: Linux 6.18 Fedora Linux 43.20260114.0 (Silverblue)
  CPU: (16) x64 AMD Ryzen 7 9800X3D 8-Core Processor
  Memory: 31.68 GB / 60.47 GB
  Container: Yes
  Shell: 5.9 - /usr/bin/zsh
Binaries:
  Node: 22.16.0 - /var/home/thomasaull/.nvm/versions/node/v22.16.0/bin/node
  npm: 10.9.2 - /var/home/thomasaull/.nvm/versions/node/v22.16.0/bin/npm
  pnpm: 10.17.1 - /var/home/thomasaull/.nvm/versions/node/v22.16.0/bin/pnpm

package.json dependencies

"dependencies": {
  "vue": "^3.5.26"
},
"devDependencies": {
  "@tsconfig/node24": "^24.0.3",
  "@types/node": "^24.10.4",
  "@vitejs/plugin-vue": "^6.0.3",
  "@vue/tsconfig": "^0.8.1",
  "npm-run-all2": "^8.0.4",
  "typescript": "~5.9.3",
  "vite": "^7.3.0",
  "vite-plugin-vue-devtools": "^8.0.5",
  "vue-tsc": "^3.2.2"
},

Steps to reproduce

Child Component

<template>
  <slot />
</template>

<script setup lang="ts">
interface Props {
  variant: 'primary' | 'secondary'
}

const props = withDefaults(defineProps<Props>(), {
  variant: 'primary',
})
</script>

Parent Component:

<script lang="ts" setup>
import Child from './Child.vue'
</script>

<template>
  <Child />
</template>

VS Code shows a type error:

Image

What is expected?

Even though the variant is technically required in the Props interface, since there is a default value, vue treats the prop as not required. The types do not reflect this.

I also did see a change in this behaviour in vue-component-meta, in v2.x there is this line where a prop with a default value is marked as not required:

if (prop.default !== undefined) {
	prop.required = false; // props with default are always optional
}

This apparently changed in v3.x

What is actually happening?

  • Type of prop with default value is still required
  • vue-component-meta v3.x marks prop with default value as required

Link to minimal reproduction

No response

Any additional comments?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions