Skip to content

Commit b16f77d

Browse files
javoskiztlevi
authored andcommitted
fix: support prop type checking for primitive wrapper objects (vuejs#6450)
close vuejs#6447
1 parent c7d3f87 commit b16f77d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/core/util/props.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ function assertType (value: any, type: Function): {
145145
let valid
146146
const expectedType = getType(type)
147147
if (simpleCheckRE.test(expectedType)) {
148-
valid = typeof value === expectedType.toLowerCase()
148+
const t = typeof value
149+
valid = t === expectedType.toLowerCase()
150+
// for primitive wrapper objects
151+
if (!valid && t === 'object') {
152+
valid = value instanceof type
153+
}
149154
} else if (expectedType === 'Object') {
150155
valid = isPlainObject(value)
151156
} else if (expectedType === 'Array') {

test/unit/features/options/props.spec.js

+11
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,17 @@ describe('Options props', () => {
206206
expect('Expected Array').toHaveBeenWarned()
207207
})
208208

209+
it('primitive wrapper objects', () => {
210+
/* eslint-disable no-new-wrappers */
211+
makeInstance(new String('s'), String)
212+
expect(console.error.calls.count()).toBe(0)
213+
makeInstance(new Number(1), Number)
214+
expect(console.error.calls.count()).toBe(0)
215+
makeInstance(new Boolean(true), Boolean)
216+
expect(console.error.calls.count()).toBe(0)
217+
/* eslint-enable no-new-wrappers */
218+
})
219+
209220
if (hasSymbol) {
210221
it('symbol', () => {
211222
makeInstance(Symbol('foo'), Symbol)

0 commit comments

Comments
 (0)