Skip to content

Commit 067c504

Browse files
committed
dx(runtime-core): warn when the prop type is []
1 parent 4fedc79 commit 067c504

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
@@ -335,7 +335,8 @@ describe('component props', () => {
335335
arr: { type: Array },
336336
obj: { type: Object },
337337
cls: { type: MyClass },
338-
fn: { type: Function }
338+
fn: { type: Function },
339+
empty: { type: [] }
339340
},
340341
setup() {
341342
return () => null
@@ -349,7 +350,8 @@ describe('component props', () => {
349350
arr: {},
350351
obj: 'false',
351352
cls: {},
352-
fn: true
353+
fn: true,
354+
empty: [1, 2, 3]
353355
}),
354356
nodeOps.createElement('div')
355357
)
@@ -374,6 +376,9 @@ describe('component props', () => {
374376
expect(
375377
`Invalid prop: type check failed for prop "cls". Expected MyClass, got Object`
376378
).toHaveBeenWarned()
379+
expect(
380+
`Prop type [] for prop "empty" won't match anything. Did you mean to use type Array instead?`
381+
).toHaveBeenWarned()
377382
})
378383

379384
// #3495

packages/runtime-core/src/componentProps.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,12 @@ function getInvalidTypeMessage(
685685
value: unknown,
686686
expectedTypes: string[]
687687
): string {
688+
if (expectedTypes.length === 0) {
689+
return (
690+
`Prop type [] for prop "${name}" won't match anything.` +
691+
` Did you mean to use type Array instead?`
692+
)
693+
}
688694
let message =
689695
`Invalid prop: type check failed for prop "${name}".` +
690696
` Expected ${expectedTypes.map(capitalize).join(' | ')}`

0 commit comments

Comments
 (0)