Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix casting symbol values to strings in the prop type check warning #10729

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/core/util/props.js
Expand Up @@ -210,7 +210,8 @@ function getInvalidTypeMessage (name, value, expectedTypes) {
// check if we need to specify expected value
if (expectedTypes.length === 1 &&
isExplicable(expectedType) &&
!isBoolean(expectedType, receivedType)) {
!isBoolean(expectedType, receivedType) &&
!isSymbol(expectedType, receivedType)) {
message += ` with value ${expectedValue}`
}
message += `, got ${receivedType} `
Expand All @@ -223,11 +224,11 @@ function getInvalidTypeMessage (name, value, expectedTypes) {

function styleValue (value, type) {
if (type === 'String') {
return `"${value}"`
return `"${String(value)}"`
} else if (type === 'Number') {
return `${Number(value)}`
return `${Number(String(value))}`
} else {
return `${value}`
return String(value)
}
}

Expand All @@ -239,3 +240,7 @@ function isExplicable (value) {
function isBoolean (...args) {
return args.some(elem => elem.toLowerCase() === 'boolean')
}

function isSymbol (...args) {
return args.some(elem => elem.toLowerCase() === 'symbol')
}
30 changes: 30 additions & 0 deletions test/unit/features/options/props.spec.js
Expand Up @@ -241,6 +241,36 @@ describe('Options props', () => {
makeInstance({}, Symbol)
expect('Expected Symbol, got Object').toHaveBeenWarned()
})

it('string & symbol', () => {
makeInstance(Symbol('foo'), String)
expect('Expected String, got Symbol').toHaveBeenWarned()
})

it('number & symbol', () => {
makeInstance(Symbol('foo'), Number)
expect('Expected Number, got Symbol').toHaveBeenWarned()
})

it('boolean & symbol', () => {
makeInstance(Symbol('foo'), Boolean)
expect('Expected Boolean, got Symbol').toHaveBeenWarned()
})

it('function & symbol', () => {
makeInstance(Symbol('foo'), Function)
expect('Expected Function, got Symbol').toHaveBeenWarned()
})

it('object & symbol', () => {
makeInstance(Symbol('foo'), Object)
expect('Expected Object, got Symbol').toHaveBeenWarned()
})

it('array & symbol', () => {
makeInstance(Symbol('foo'), Array)
expect('Expected Array, got Symbol').toHaveBeenWarned()
})
}

it('custom constructor', () => {
Expand Down