]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
dx(runtime-core): warn when the prop type is `[]` (#7608)
authorskirtle <65301168+skirtles-code@users.noreply.github.com>
Fri, 10 Nov 2023 06:32:10 +0000 (06:32 +0000)
committerGitHub <noreply@github.com>
Fri, 10 Nov 2023 06:32:10 +0000 (14:32 +0800)
packages/runtime-core/__tests__/componentProps.spec.ts
packages/runtime-core/src/componentProps.ts

index 89112f2ad49edf8874fc39051d9db53ba6a95dd0..885e80090a1417b2e4a33db28d541a8c6efbb177 100644 (file)
@@ -336,7 +336,8 @@ describe('component props', () => {
         obj: { type: Object },
         cls: { type: MyClass },
         fn: { type: Function },
-        skipCheck: { type: [Boolean, Function], skipCheck: true }
+        skipCheck: { type: [Boolean, Function], skipCheck: true },
+        empty: { type: [] }
       },
       setup() {
         return () => null
@@ -351,7 +352,8 @@ describe('component props', () => {
         obj: 'false',
         cls: {},
         fn: true,
-        skipCheck: 'foo'
+        skipCheck: 'foo',
+        empty: [1, 2, 3]
       }),
       nodeOps.createElement('div')
     )
@@ -379,6 +381,9 @@ describe('component props', () => {
     expect(
       `Invalid prop: type check failed for prop "skipCheck". Expected Boolean | Function, got String with value "foo".`
     ).not.toHaveBeenWarned()
+    expect(
+      `Prop type [] for prop "empty" won't match anything. Did you mean to use type Array instead?`
+    ).toHaveBeenWarned()
   })
 
   // #3495
index 4d40278955594da08eed1a6c709f6310e7f4a495..3a1798b934b962d352a7506ae01fc68ffce70a68 100644 (file)
@@ -725,6 +725,12 @@ function getInvalidTypeMessage(
   value: unknown,
   expectedTypes: 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 =
     `Invalid prop: type check failed for prop "${name}".` +
     ` Expected ${expectedTypes.map(capitalize).join(' | ')}`