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

close #6447
This commit is contained in:
AchillesJ 2017-09-06 04:23:53 +08:00 committed by Evan You
parent 08bc7595fd
commit 679cd1fef4
2 changed files with 17 additions and 1 deletions

View File

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

View File

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