Skip to content

Commit b52883c

Browse files
committedSep 17, 2019
fix(props): correctly warn when a provided prop is Symbol
Fixes #10519
1 parent 95d8afa commit b52883c

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed
 

‎src/core/util/props.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -205,18 +205,19 @@ function getInvalidTypeMessage (name, value, expectedTypes) {
205205
` Expected ${expectedTypes.map(capitalize).join(', ')}`
206206
const expectedType = expectedTypes[0]
207207
const receivedType = toRawType(value)
208-
const expectedValue = styleValue(value, expectedType)
209-
const receivedValue = styleValue(value, receivedType)
210208
// check if we need to specify expected value
211-
if (expectedTypes.length === 1 &&
212-
isExplicable(expectedType) &&
213-
!isBoolean(expectedType, receivedType)) {
214-
message += ` with value ${expectedValue}`
209+
if (
210+
expectedTypes.length === 1 &&
211+
isExplicable(expectedType) &&
212+
isExplicable(typeof value) &&
213+
!isBoolean(expectedType, receivedType)
214+
) {
215+
message += ` with value ${styleValue(value, expectedType)}`
215216
}
216217
message += `, got ${receivedType} `
217218
// check if we need to specify received value
218219
if (isExplicable(receivedType)) {
219-
message += `with value ${receivedValue}.`
220+
message += `with value ${styleValue(value, receivedType)}.`
220221
}
221222
return message
222223
}
@@ -231,9 +232,9 @@ function styleValue (value, type) {
231232
}
232233
}
233234

234-
function isExplicable (value) {
235-
const explicitTypes = ['string', 'number', 'boolean']
236-
return explicitTypes.some(elem => value.toLowerCase() === elem)
235+
const EXPLICABLE_TYPES = ['string', 'number', 'boolean']
236+
function isExplicable(value) {
237+
return EXPLICABLE_TYPES.some(elem => value.toLowerCase() === elem)
237238
}
238239

239240
function isBoolean (...args) {

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

+10
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,16 @@ describe('Options props', () => {
241241
makeInstance({}, Symbol)
242242
expect('Expected Symbol, got Object').toHaveBeenWarned()
243243
})
244+
245+
it('warns when expected an explicable type but Symbol was provided', () => {
246+
makeInstance(Symbol('foo'), String)
247+
expect('Expected String, got Symbol').toHaveBeenWarned()
248+
})
249+
250+
it('warns when expected an explicable type but Symbol was provided', () => {
251+
makeInstance(Symbol('foo'), [String, Number])
252+
expect('Expected String, Number, got Symbol').toHaveBeenWarned()
253+
})
244254
}
245255

246256
it('custom constructor', () => {

0 commit comments

Comments
 (0)