🙆

Vue3のdefinePropsの分割代入をリアクティブにする& withDefaults が非推奨になるPRがマージされてた

2023/04/04に公開

definePropsの分割代入をリアクティブにする & withDefaults が非推奨 になるPRがマージされてた!
Vue 3.3 で対応されそう!

<script setup lang="ts">
const { foo = 1, bar = 'ok' } = defineProps<{ foo?: number, bar?: string }>()
</script>

https://github.com/vuejs/core/pull/7986

いままでは、definePropsの分割代入でにリアクティブの消失や、型宣言使用時のdefault値の宣言が冗長になってしまう問題があります。これが解消されそう!

export interface Props {
  msg?: string
  labels?: string[]
}

const props = withDefaults(defineProps<Props>(), {
  msg: 'hello',
  labels: () => ['one', 'two']
})

Discussion