]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(types): better typing for direct setup signature of defineComponent (#10357)
authorShean de Montigny-Desautels <s.montigny-desautels@softdb.com>
Sun, 25 Feb 2024 13:10:08 +0000 (08:10 -0500)
committerGitHub <noreply@github.com>
Sun, 25 Feb 2024 13:10:08 +0000 (21:10 +0800)
close #8604
close #8855

packages/runtime-core/src/apiDefineComponent.ts

index 47bcf9f2acb5e8a0f52acb1d7be4ef636eaa2872..d63bd8314e745dbcc55649ea052cf2f41f63480f 100644 (file)
@@ -89,6 +89,30 @@ export type DefineComponent<
   > &
   PP
 
+type DirectSetupComponent<
+  P extends Record<string, any>,
+  E extends EmitsOptions = {},
+  S extends SlotsType = SlotsType,
+  Props = P & EmitsToProps<E>,
+  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<E>) => any
+): DirectSetupComponent<Props, E, S>
 export function defineComponent<
   Props extends Record<string, any>,
   E extends EmitsOptions = {},
@@ -127,7 +151,7 @@ export function defineComponent<
     emits?: E | EE[]
     slots?: S
   },
-): (props: Props & EmitsToProps<E>) => any
+): DirectSetupComponent<Props, E, S>
 
 // overload 2: object format with no props
 // (uses user defined props interface)