Skip to content

Commit a5491e1

Browse files
dx(runtime-core): warn when the prop type is [] (#7608)
1 parent 58e2a94 commit a5491e1

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

packages/runtime-core/__tests__/componentProps.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ describe('component props', () => {
336336
obj: { type: Object },
337337
cls: { type: MyClass },
338338
fn: { type: Function },
339-
skipCheck: { type: [Boolean, Function], skipCheck: true }
339+
skipCheck: { type: [Boolean, Function], skipCheck: true },
340+
empty: { type: [] }
340341
},
341342
setup() {
342343
return () => null
@@ -351,7 +352,8 @@ describe('component props', () => {
351352
obj: 'false',
352353
cls: {},
353354
fn: true,
354-
skipCheck: 'foo'
355+
skipCheck: 'foo',
356+
empty: [1, 2, 3]
355357
}),
356358
nodeOps.createElement('div')
357359
)
@@ -379,6 +381,9 @@ describe('component props', () => {
379381
expect(
380382
`Invalid prop: type check failed for prop "skipCheck". Expected Boolean | Function, got String with value "foo".`
381383
).not.toHaveBeenWarned()
384+
expect(
385+
`Prop type [] for prop "empty" won't match anything. Did you mean to use type Array instead?`
386+
).toHaveBeenWarned()
382387
})
383388

384389
// #3495

packages/runtime-core/src/componentProps.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,12 @@ function getInvalidTypeMessage(
725725
value: unknown,
726726
expectedTypes: string[]
727727
): string {
728+
if (expectedTypes.length === 0) {
729+
return (
730+
`Prop type [] for prop "${name}" won't match anything.` +
731+
` Did you mean to use type Array instead?`
732+
)
733+
}
728734
let message =
729735
`Invalid prop: type check failed for prop "${name}".` +
730736
` Expected ${expectedTypes.map(capitalize).join(' | ')}`

0 commit comments

Comments
 (0)