Browse Source

fix: support prop type checking for primitive wrapper objects (#6450)

close #6447
dev
AchillesJ 7 years ago
committed by Evan You
parent
commit
679cd1fef4
  1. 7
      src/core/util/props.js
  2. 11
      test/unit/features/options/props.spec.js

7
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') {

11
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)

Loading…
Cancel
Save