From: Carlos Rodrigues Date: Wed, 19 Aug 2020 20:36:42 +0000 (+0100) Subject: fix(types): handling PropType with default value (#1896) X-Git-Tag: v3.0.0-rc.6~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c2913d57d14449775faf1f2e5647e6d1f3d3f920;p=thirdparty%2Fvuejs%2Fcore.git fix(types): handling PropType with default value (#1896) fix #1891 --- diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index 48636f6553..90abf4149f 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -47,7 +47,7 @@ type DefaultFactory = (props: Data) => T | null | undefined interface PropOptions { type?: PropType | true | null required?: boolean - default?: D | DefaultFactory | null | undefined + default?: D | DefaultFactory | null | undefined | object validator?(value: unknown): boolean } diff --git a/test-dts/defineComponent.test-d.tsx b/test-dts/defineComponent.test-d.tsx index 00dbe3c13a..7a88c40bc4 100644 --- a/test-dts/defineComponent.test-d.tsx +++ b/test-dts/defineComponent.test-d.tsx @@ -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(props.fff) expectType(props.hhh) expectType(props.ggg) + expectType(props.ffff) expectType(props.validated) // @ts-expect-error props should be readonly