mirror of https://github.com/vuejs/core.git
dx(runtime-core): warn when the prop type is `[]` (#7608)
This commit is contained in:
parent
58e2a94871
commit
a5491e1cdd
|
@ -336,7 +336,8 @@ describe('component props', () => {
|
||||||
obj: { type: Object },
|
obj: { type: Object },
|
||||||
cls: { type: MyClass },
|
cls: { type: MyClass },
|
||||||
fn: { type: Function },
|
fn: { type: Function },
|
||||||
skipCheck: { type: [Boolean, Function], skipCheck: true }
|
skipCheck: { type: [Boolean, Function], skipCheck: true },
|
||||||
|
empty: { type: [] }
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
return () => null
|
return () => null
|
||||||
|
@ -351,7 +352,8 @@ describe('component props', () => {
|
||||||
obj: 'false',
|
obj: 'false',
|
||||||
cls: {},
|
cls: {},
|
||||||
fn: true,
|
fn: true,
|
||||||
skipCheck: 'foo'
|
skipCheck: 'foo',
|
||||||
|
empty: [1, 2, 3]
|
||||||
}),
|
}),
|
||||||
nodeOps.createElement('div')
|
nodeOps.createElement('div')
|
||||||
)
|
)
|
||||||
|
@ -379,6 +381,9 @@ describe('component props', () => {
|
||||||
expect(
|
expect(
|
||||||
`Invalid prop: type check failed for prop "skipCheck". Expected Boolean | Function, got String with value "foo".`
|
`Invalid prop: type check failed for prop "skipCheck". Expected Boolean | Function, got String with value "foo".`
|
||||||
).not.toHaveBeenWarned()
|
).not.toHaveBeenWarned()
|
||||||
|
expect(
|
||||||
|
`Prop type [] for prop "empty" won't match anything. Did you mean to use type Array instead?`
|
||||||
|
).toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
|
|
||||||
// #3495
|
// #3495
|
||||||
|
|
|
@ -725,6 +725,12 @@ function getInvalidTypeMessage(
|
||||||
value: unknown,
|
value: unknown,
|
||||||
expectedTypes: string[]
|
expectedTypes: string[]
|
||||||
): string {
|
): string {
|
||||||
|
if (expectedTypes.length === 0) {
|
||||||
|
return (
|
||||||
|
`Prop type [] for prop "${name}" won't match anything.` +
|
||||||
|
` Did you mean to use type Array instead?`
|
||||||
|
)
|
||||||
|
}
|
||||||
let message =
|
let message =
|
||||||
`Invalid prop: type check failed for prop "${name}".` +
|
`Invalid prop: type check failed for prop "${name}".` +
|
||||||
` Expected ${expectedTypes.map(capitalize).join(' | ')}`
|
` Expected ${expectedTypes.map(capitalize).join(' | ')}`
|
||||||
|
|
Loading…
Reference in New Issue