Subscribe on changes!

defineProps options object loses properties when using generics

avatar
Nov 4th 2023

Vue version

3.3.7 & 3.4.alpha

Link to minimal reproduction

https://play.vuejs.org/#eNqNUk1v2zAM/SuELt2Axj70MMBIi25DD9thLbYcdXFsxlVmUxolpxkC//fS8kfT9AO9UXyP5OOjDuqrc8muRZWppS/YuAAeQ+ugzqm61Cp4raBCQjaFPFdaXWkyjbMc4AB3bN3qv0PoYMO2gTPpdKapsOQDOAE9XEKJG0PYU/2ngyaAPIPb9RaLALmfWyxXV+eaenidQaQBBMm/we0J3VhQfKRAuD2D8V9rGMsMArcYk52m7nPfKQpO8ilYT0GhaZkO5shcda6G/RdN7pKttyTexfl6BMSyWZFWYkn/1uo+BOezNC1KkrISa7PjhDCk5Jr0WmgptxRMg4vSNtcXyUXyJS2ND8fpBH2zWLN98MjSRKtxrTgmleQOecFIJTLyR8eelB2PPoFejJ/8E1OCl7NvTHViSWEbZ2rkWxeMfItn1uR1bR9+xtx8jVhzj8XfV/Jbvx92umOMyo72DzlXGAb45s8v3Es8g40t23o8wxvgb/S2bnuNA+1bS6XIPuJFtT/ihQ1VK3+zD0h+WqoXOn3K8R7f31n9Sa64PbvYPQLEQTNC

Steps to reproduce

image
<script setup lang="ts" generic="T">
import { PropType } from 'vue'
const props = defineProps({
  a: Object as PropType<T>,

  b: {
    type: Object as PropType<T>
  },

  c: {
    type: Object as PropType<T>,
    required: true,
  }
})

props.a
props.b
props.c
</script>

What is expected?

The props to be declared correctly

What is actually happening?

Properties are been excluded from props, unless they are required 🤔

System Info

No response

Any additional comments?

No response

avatar
Nov 6th 2023

You should add the type property to define the props object.

<script setup lang="ts" generic="T">
import { PropType } from 'vue'
const props = defineProps({
  a: {
    type: Object as PropType<T>,
  },
  b: {
    type: Object as PropType<T>,
  },

  c: {
    type: Object as PropType<T>,
    required: true,
  },
})

props.a
props.b
props.c
</script>

You can see: https://deepscan.io/docs/rules/vue-bad-prop-decl#:~:text=This%20rule%20applies%20when%20a,an%20object%20with%20validation%20requirements.