vuejs / vuejs/docs

Document error about defining the default value of Object type props

Open
#1,200 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Vue
Stars
3.2k
Forks
5k
Avg merge
14d 17h
Merged PRs (30d)
1

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Vue documentation example for defining an Object prop default and compare it with the two TypeScript snippets in the issue. Confirm which syntax produces the type error, then update the documented example or explanation so it accurately describes the supported form and verify the documentation change in the affected page.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.