Skip to content

Commit

Permalink
fix: support prop type checking for primitive wrapper objects (#6450)
Browse files Browse the repository at this point in the history
close #6447
  • Loading branch information
javoski authored and yyx990803 committed Sep 5, 2017
1 parent 08bc759 commit 679cd1f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/core/util/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
11 changes: 11 additions & 0 deletions test/unit/features/options/props.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 679cd1f

Please sign in to comment.