diff --git a/src/core/util/props.js b/src/core/util/props.js index bea6c92691e..9e69913422e 100644 --- a/src/core/util/props.js +++ b/src/core/util/props.js @@ -31,7 +31,10 @@ export function validateProp ( if (isType(Boolean, prop.type)) { if (absent && !hasOwn(prop, 'default')) { value = false - } else if (!isType(String, prop.type) && (value === '' || value === hyphenate(key))) { + } else if ( + (!isType(String, prop.type) || prop.type.indexOf(String) > prop.type.indexOf(Boolean)) && + (value === '' || value === hyphenate(key)) + ) { value = true } } diff --git a/test/unit/features/component/component.spec.js b/test/unit/features/component/component.spec.js index 34c037a1e74..c3afc110073 100644 --- a/test/unit/features/component/component.spec.js +++ b/test/unit/features/component/component.spec.js @@ -276,6 +276,23 @@ describe('Component', () => { expect(vm.$el.outerHTML).toBe('') }) + it('must consider the order of props when using Boolean and String types', () => { + const vm = new Vue({ + template: '', + components: { + test: { + template: '
', + props: { + booleanOrString: [Boolean, String], + stringOrBoolean: [String, Boolean] + } + } + } + }).$mount() + expect(vm.$refs.test.$props.booleanOrString).toBe(true) + expect(vm.$refs.test.$props.stringOrBoolean).toBe('') + }) + it('should warn when using camelCased props in in-DOM template', () => { new Vue({ data: {