Subscribe on changes!

`props` object does not define optional properties without default

avatar
Mar 29th 2021

Version

3.0.9

Reproduction link

repo

<template>
  <h1>{{ keys }}</h1>
</template>

<script>
 import { defineComponent } from 'vue'
  
export default defineComponent({
  props: {
    notDefined: String,
    defined: {
      type: String,
      default: undefined,
    },
  },
  setup(props) {
    const keys = Object.keys(props);

    // keys: ['defined']
    // instead of 
    // keys: ['notDefined', 'defined']
    return {
      keys
    }
  },
});
</script>

Steps to reproduce

  • Declare an optional prop: foo: String
  • do 'foo in props
  • it will be false because foo is not defined in the props object

What is expected?

props should contain that property foo defined

What is actually happening?

props is an empty object {}