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

feat: Add a test case to require-valid-default-prop #2637

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aryehb
Copy link

@aryehb aryehb commented Dec 3, 2024

The documentation for Vue props, as well as the require-valid-default-prop rule, are not clear if setting a default value of null to a prop with type Object requires a factory function:

props: {
  foo: { type: Object, default: () => null },
},

vs.

props: {
  foo: { type: Object, default: null },
},

On one hand, typeof null === 'object'. On the other hand, the reason for using a factory function is so each instance of the prop has a different object reference, whereas null is always the same reference anyway.

This adds a valid test case for setting a default value of null to a prop with type Object without a factory function. The test passes, so it's evident that null does not require a factory function.

The documentation for Vue props, as well as the `require-valid-default-prop` rule, are not clear if setting a default value of `null` to a prop with type `Object` requires a factory function.

On one hand, `typeof null === 'object'`. On the other hand, the reason
for using a factory function is so each instance of the prop has a
different object reference, whereas `null` is always the same reference
anyway.

This adds a valid test case for setting a default value of `null` to a
prop with type `Object` without a factory function. The test passes, so
it's evident that `null` does not require a factory function.
Copy link
Member

@FloEdelmann FloEdelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you!

@FloEdelmann FloEdelmann requested a review from ota-meshi December 3, 2024 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants