docs icon indicating copy to clipboard operation
docs copied to clipboard

Document error about defining the default value of Object type props

Open CNMathon opened this issue 4 years ago • 3 comments

You can define the Object type props like this. It will work fine.

export default defineComponent({
  props: {
    newProp: {
      type: Object
      default: () => {
        return {
          a: 1
        }
      }
    }
  }
})

But if you define the prop like this, it will throw a type error.

export default defineComponent({
  props: {
    newProp: {
      type: Object
      default() {
        return {
          a: 1
        }
      }
    }
  }
})

The documentation shows a code similar to the second paragraph.

CNMathon avatar Aug 23 '21 08:08 CNMathon

mentioned document

Here is the location of the mentioned document.

CNMathon avatar Aug 23 '21 08:08 CNMathon

I believe the examples in the documentation are correct, though there are some considerations when adapting them to TypeScript:

https://v3.vuejs.org/guide/typescript-support.html#annotating-props

Maybe we should include the above link in that earlier guide?

skirtles-code avatar Aug 24 '21 23:08 skirtles-code

@skirtles-code I believe we should add a note to the TS guide rather than to the default (as default works in the non-TS environment). Alternatively, we can change all examples to use arrow functions from the starts - this will resolve the concern without adding anything to TS guide

NataliaTepluhina avatar Oct 16 '21 11:10 NataliaTepluhina