Skip to content

Commit b47d773

Browse files
Ivan Agafonovyyx990803
Ivan Agafonov
authored andcommitted
support short prop declaration as prop: true (#3643)
1 parent 4c7a87e commit b47d773

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/core/util/props.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function assertProp (
9191
return
9292
}
9393
let type = prop.type
94-
let valid = !type
94+
let valid = !type || type === true
9595
const expectedTypes = []
9696
if (type) {
9797
if (!Array.isArray(type)) {

test/unit/features/options/props.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,19 @@ describe('Options props', () => {
244244
expect(console.error.calls.count()).toBe(2)
245245
expect('Expected Boolean').toHaveBeenWarned()
246246
})
247+
248+
it('optional prop of any type (type: true or prop: true)', () => {
249+
makeInstance(1, true)
250+
expect(console.error.calls.count()).toBe(0)
251+
makeInstance('any', true)
252+
expect(console.error.calls.count()).toBe(0)
253+
makeInstance({}, true)
254+
expect(console.error.calls.count()).toBe(0)
255+
makeInstance(undefined, true)
256+
expect(console.error.calls.count()).toBe(0)
257+
makeInstance(null, true)
258+
expect(console.error.calls.count()).toBe(0)
259+
})
247260
})
248261

249262
it('should warn data fields already defined as a prop', () => {

0 commit comments

Comments
 (0)