]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(types): handling PropType<Function> with default value (#1896)
authorCarlos Rodrigues <david-181@hotmail.com>
Wed, 19 Aug 2020 20:36:42 +0000 (21:36 +0100)
committerGitHub <noreply@github.com>
Wed, 19 Aug 2020 20:36:42 +0000 (16:36 -0400)
fix #1891

packages/runtime-core/src/componentProps.ts
test-dts/defineComponent.test-d.tsx

index 48636f6553c7f62b7347611560c9791e25d40a70..90abf4149f04856854bc430e739c652239905476 100644 (file)
@@ -47,7 +47,7 @@ type DefaultFactory<T> = (props: Data) => T | null | undefined
 interface PropOptions<T = any, D = T> {
   type?: PropType<T> | true | null
   required?: boolean
-  default?: D | DefaultFactory<D> | null | undefined
+  default?: D | DefaultFactory<D> | null | undefined | object
   validator?(value: unknown): boolean
 }
 
index 00dbe3c13aadad59fa29565de6dda6a793f2b95c..7a88c40bc4e51d329354d61a1987456075531052 100644 (file)
@@ -30,6 +30,7 @@ describe('with object props', () => {
     fff: (a: number, b: string) => { a: boolean }
     hhh: boolean
     ggg: 'foo' | 'bar'
+    ffff: (a: number, b: string) => { a: boolean }
     validated?: string
   }
 
@@ -90,6 +91,11 @@ describe('with object props', () => {
         type: String as PropType<'foo' | 'bar'>,
         default: 'foo'
       },
+      // default + function
+      ffff: {
+        type: Function as PropType<(a: number, b: string) => { a: boolean }>,
+        default: (a: number, b: string) => ({ a: true })
+      },
       validated: {
         type: String,
         // validator requires explicit annotation
@@ -113,6 +119,7 @@ describe('with object props', () => {
       expectType<ExpectedProps['fff']>(props.fff)
       expectType<ExpectedProps['hhh']>(props.hhh)
       expectType<ExpectedProps['ggg']>(props.ggg)
+      expectType<ExpectedProps['ffff']>(props.ffff)
       expectType<ExpectedProps['validated']>(props.validated)
 
       // @ts-expect-error props should be readonly