From 679cd1fef448989bf645313c391e4134ecd9f593 Mon Sep 17 00:00:00 2001 From: AchillesJ Date: Wed, 6 Sep 2017 04:23:53 +0800 Subject: [PATCH] fix: support prop type checking for primitive wrapper objects (#6450) close #6447 --- src/core/util/props.js | 7 ++++++- test/unit/features/options/props.spec.js | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/core/util/props.js b/src/core/util/props.js index 385347bd82..3e57ae8e4f 100644 --- a/src/core/util/props.js +++ b/src/core/util/props.js @@ -145,7 +145,12 @@ function assertType (value: any, type: Function): { let valid const expectedType = getType(type) if (simpleCheckRE.test(expectedType)) { - valid = typeof value === expectedType.toLowerCase() + const t = typeof value + valid = t === expectedType.toLowerCase() + // for primitive wrapper objects + if (!valid && t === 'object') { + valid = value instanceof type + } } else if (expectedType === 'Object') { valid = isPlainObject(value) } else if (expectedType === 'Array') { diff --git a/test/unit/features/options/props.spec.js b/test/unit/features/options/props.spec.js index 818f2af61b..35348d2457 100644 --- a/test/unit/features/options/props.spec.js +++ b/test/unit/features/options/props.spec.js @@ -206,6 +206,17 @@ describe('Options props', () => { expect('Expected Array').toHaveBeenWarned() }) + it('primitive wrapper objects', () => { + /* eslint-disable no-new-wrappers */ + makeInstance(new String('s'), String) + expect(console.error.calls.count()).toBe(0) + makeInstance(new Number(1), Number) + expect(console.error.calls.count()).toBe(0) + makeInstance(new Boolean(true), Boolean) + expect(console.error.calls.count()).toBe(0) + /* eslint-enable no-new-wrappers */ + }) + if (hasSymbol) { it('symbol', () => { makeInstance(Symbol('foo'), Symbol)