]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
types: support object as props type (#3165)
authorHcySunYang <HcySunYang@outlook.com>
Wed, 24 Feb 2021 21:20:41 +0000 (05:20 +0800)
committerGitHub <noreply@github.com>
Wed, 24 Feb 2021 21:20:41 +0000 (16:20 -0500)
packages/runtime-core/src/componentProps.ts
test-dts/component.test-d.ts

index f30c238e9da28cf786d9b84c86a021deeb6ad67f..f672446446bf25b9c7de2f65d201c1d7787aa3b5 100644 (file)
@@ -56,7 +56,7 @@ interface PropOptions<T = any, D = T> {
 export type PropType<T> = PropConstructor<T> | PropConstructor<T>[]
 
 type PropConstructor<T = any> =
-  | { new (...args: any[]): T & object }
+  | { new (...args: any[]): T & {} }
   | { (): T }
   | PropMethod<T>
 
index 30b3b8e5f53eb19f6ecbe48c2a33ba174f8de5f8..06368e377787b17e5241b4daade6402bb531fdb2 100644 (file)
@@ -39,6 +39,7 @@ describe('object props', () => {
     ggg: 'foo' | 'bar'
     ffff: (a: number, b: string) => { a: boolean }
     validated?: string
+    object?: object
   }
 
   describe('defineComponent', () => {
@@ -106,7 +107,8 @@ describe('object props', () => {
           type: String,
           // validator requires explicit annotation
           validator: (val: unknown) => val !== ''
-        }
+        },
+        object: Object as PropType<object>
       },
       setup(props) {
         return {
@@ -140,6 +142,7 @@ describe('object props', () => {
     expectType<ExpectedProps['ggg']>(props.ggg)
     expectType<ExpectedProps['ffff']>(props.ffff)
     expectType<ExpectedProps['validated']>(props.validated)
+    expectType<ExpectedProps['object']>(props.object)
 
     // raw bindings
     expectType<Number>(rawBindings.setupA)
@@ -263,7 +266,8 @@ describe('object props', () => {
           type: String,
           // validator requires explicit annotation
           validator: (val: unknown) => val !== ''
-        }
+        },
+        object: Object as PropType<object>
       },
 
       setup() {
@@ -293,6 +297,7 @@ describe('object props', () => {
     expectType<ExpectedProps['ggg']>(props.ggg)
     // expectType<ExpectedProps['ffff']>(props.ffff) // todo fix
     expectType<ExpectedProps['validated']>(props.validated)
+    expectType<ExpectedProps['object']>(props.object)
 
     // rawBindings
     expectType<Number>(rawBindings.setupA)