Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

props object does not define optional properties without default #3516

Closed
pikax opened this issue Mar 29, 2021 · 1 comment
Closed

props object does not define optional properties without default #3516

pikax opened this issue Mar 29, 2021 · 1 comment

Comments

@pikax
Copy link
Member

pikax commented Mar 29, 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 {}

@posva
Copy link
Member

posva commented Mar 29, 2021

Duplicate of #3288

@posva posva marked this as a duplicate of #3288 Mar 29, 2021
@posva posva closed this as completed Mar 29, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Oct 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants