diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index 48636f6553c..90abf4149f0 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 00dbe3c13aa..7a88c40bc4e 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