Skip to content

Commit f2d3f3a

Browse files
committed
feat: Add a test case to require-valid-default-prop
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.
1 parent a2abbf0 commit f2d3f3a

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

tests/lib/rules/require-valid-default-prop.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ ruleTester.run('require-valid-default-prop', rule, {
108108
foo: { type: String, default () { return Foo } },
109109
foo: { type: Number, default () { return Foo } },
110110
foo: { type: Object, default () { return Foo } },
111+
foo: { type: Object, default: null },
111112
}
112113
})`,
113114
languageOptions

0 commit comments

Comments
 (0)