From 7c654a4e17ee433d6ec4556d1a1b0ecf1cf76ef4 Mon Sep 17 00:00:00 2001 From: Shean de Montigny-Desautels Date: Sun, 25 Feb 2024 08:10:08 -0500 Subject: [PATCH] fix(types): better typing for direct setup signature of defineComponent (#10357) close #8604 close #8855 --- .../runtime-core/src/apiDefineComponent.ts | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/runtime-core/src/apiDefineComponent.ts b/packages/runtime-core/src/apiDefineComponent.ts index 47bcf9f2acb..d63bd8314e7 100644 --- a/packages/runtime-core/src/apiDefineComponent.ts +++ b/packages/runtime-core/src/apiDefineComponent.ts @@ -89,6 +89,30 @@ export type DefineComponent< > & PP +type DirectSetupComponent< + P extends Record, + E extends EmitsOptions = {}, + S extends SlotsType = SlotsType, + Props = P & EmitsToProps, + PP = PublicProps, +> = new ( + props: Props & PP, +) => CreateComponentPublicInstance< + Props, + {}, + {}, + {}, + {}, + ComponentOptionsMixin, + ComponentOptionsMixin, + E, + PP, + {}, + false, + {}, + S +> + // defineComponent is a utility that is primarily used for type inference // when declaring components. Type inference is provided in the component // options (provided as the argument). The returned value has artificial types @@ -111,7 +135,7 @@ export function defineComponent< emits?: E | EE[] slots?: S }, -): (props: Props & EmitsToProps) => any +): DirectSetupComponent export function defineComponent< Props extends Record, E extends EmitsOptions = {}, @@ -127,7 +151,7 @@ export function defineComponent< emits?: E | EE[] slots?: S }, -): (props: Props & EmitsToProps) => any +): DirectSetupComponent // overload 2: object format with no props // (uses user defined props interface)