Skip to content

Commit

Permalink
fix: support prop type checking for primitive wrapper objects (vuejs#…
Browse files Browse the repository at this point in the history
  • Loading branch information
javoski authored and ztlevi committed Feb 14, 2018
1 parent c7d3f87 commit b16f77d
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 b16f77d

Please sign in to comment.