Skip to content

[v3.5.x] destructure from defineProps with withDefaults throw an error #11930

@zhaojjiang

Description

@zhaojjiang

Vue version

3.5.5

Link to minimal reproduction

https://play.vuejs.org/#eNp9kctOwzAQRX9l8CatVFohWFVpEY9KwAIqQGLjTZROUhfHtuxJWynKvzNx1McCdeXM3DvxuZ5GPDg33tYopiINuVeOICDVDnRmypkUFKSYS6MqZz1BAx4LaKHwtoKExxJppMmtCQRVKGHW6YPkBbW28GO9Xl0lw5OlAUI+WvbtFK2fschqTWGwwkIZXHrrQtpIA9F2P4VAXplSmnY+GI7gqEwh6Q6+u+Wfp5Oemym5IKyczgi5AkjXN/OmiWRtm064il1lXE2wva7sCjVnZF0KmLCYTs7mxYjTM3ihyvEmWMNPFBGkyG3llEb/4UhxMCmmPVynZRx99xZ75GscHfr5GvPff/qbsO96Uiw9BvRblOKoUeZLpF5efL3jnr+PItPXmt0XxE8MVtcdY297rM2Ksc98kfY1Lpdf+jss9oQmHEJ1oJ2zjX4peOFPF6KfcG/Hd3GONyTaP1bly/I=

Steps to reproduce

create new project

// App.vue

<script setup lang="ts">
const { test } = withDefaults(defineProps<{
  test?: string
}>(), {
  test: 'test'
})
</script>

throw error:

error during build:
[vite:vue] [@vue/compiler-sfc] withDefaults() is unnecessary when using destructure with defineProps().
Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(...).

D:/temp/vite/src/App.vue
1  |  <script setup lang="ts">
2  |  const { test } = withDefaults(defineProps<{
   |                   ^^^^^^^^^^^^
3  |    test?: string
4  |  }>(), {

What is expected?

It should not throw an error and shoule not break build, just keep it warning,

Or, if withDefaults not marked as deprecated, it should work without any warn or error messages

What is actually happening?

It breaks build

System Info

No response

Any additional comments?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions