From: Carlos Rodrigues Date: Mon, 23 Aug 2021 23:04:03 +0000 (+0100) Subject: types(PropType): Allow `undefined` function to be used on `PropType` (#4405) X-Git-Tag: v3.2.5~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=afd49b3e8808f6f2bb52d6ca3de25a40191ae712;p=thirdparty%2Fvuejs%2Fcore.git types(PropType): Allow `undefined` function to be used on `PropType` (#4405) --- diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index 7d7f3a3872..7218d22288 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -66,7 +66,9 @@ type PropConstructor = | { (): T } | PropMethod -type PropMethod = [T] extends [(...args: any) => any] // if is function with args +type PropMethod = [T] extends [ + ((...args: any) => any) | undefined +] // if is function with args, allowing non-required functions ? { new (): TConstructor; (): T; readonly prototype: TConstructor } // Create Function like constructor : never diff --git a/test-dts/defineComponent.test-d.tsx b/test-dts/defineComponent.test-d.tsx index 9569b585f5..4766bddb4b 100644 --- a/test-dts/defineComponent.test-d.tsx +++ b/test-dts/defineComponent.test-d.tsx @@ -21,6 +21,7 @@ describe('with object props', () => { b: string e?: Function h: boolean + j: undefined | (() => string | undefined) bb: string bbb: string bbbb: string | undefined @@ -55,6 +56,7 @@ describe('with object props', () => { }, e: Function, h: Boolean, + j: Function as PropType string | undefined)>, // default value should infer type and make it non-void bb: { default: 'hello' @@ -137,6 +139,7 @@ describe('with object props', () => { expectType(props.b) expectType(props.e) expectType(props.h) + expectType(props.j) expectType(props.bb) expectType(props.bbb) expectType(props.bbbb)