Browse Source

fix(runtime-core): remove constructor props for defineComponent (#14223)

zhiyuanzmj 4 months ago
parent
commit
ad0a237138

+ 14 - 15
packages-private/dts-test/defineComponent.test-d.tsx

@@ -1880,22 +1880,21 @@ interface ErrorMessageSlotProps {
  * component types generated by vue-tsc
  * relying on legacy CreateComponentPublicInstance signature
  */
-type Props = Readonly<
-  vue.ExtractPropTypes<{
-    as: {
-      type: StringConstructor
-      default: any
-    }
-    name: {
-      type: StringConstructor
-      required: true
-    }
-  }> &
-    vue.AllowedComponentProps
->
 declare const ErrorMessage: {
-  new (props: Props): vue.CreateComponentPublicInstance<
-    Props,
+  new (...args: any[]): vue.CreateComponentPublicInstance<
+    Readonly<
+      vue.ExtractPropTypes<{
+        as: {
+          type: StringConstructor
+          default: any
+        }
+        name: {
+          type: StringConstructor
+          required: true
+        }
+      }> &
+        vue.AllowedComponentProps
+    >,
     () =>
       | VNode<
           vue.RendererNode,

+ 6 - 0
packages-private/dts-test/vapor/jsx.d.ts

@@ -3,6 +3,12 @@ import type { NativeElements, ReservedProps, VaporRenderResult } from 'vue'
 declare global {
   namespace JSX {
     export type Element = VaporRenderResult
+    export interface ElementClass {
+      props: {}
+    }
+    export interface ElementAttributesProperty {
+      props: {}
+    }
     export interface IntrinsicElements extends NativeElements {
       [name: string]: any
     }

+ 1 - 3
packages/runtime-core/src/component.ts

@@ -114,9 +114,7 @@ export type Data = Record<string, unknown>
  * declare const instance: ComponentInstance<typeof MyComp>
  * ```
  */
-export type ComponentInstance<T> = T extends {
-  new (...args: any[]): ComponentPublicInstance
-}
+export type ComponentInstance<T> = T extends { new (): ComponentPublicInstance }
   ? InstanceType<T>
   : T extends FunctionalComponent<infer Props, infer Emits>
     ? ComponentPublicInstance<Props, {}, {}, {}, {}, ShortEmitsToObject<Emits>>

+ 1 - 1
packages/runtime-core/src/componentPublicInstance.ts

@@ -144,7 +144,7 @@ export type ComponentPublicInstanceConstructor<
   __isFragment?: never
   __isTeleport?: never
   __isSuspense?: never
-  new (props?: T['$props']): T
+  new (...args: any[]): T
 }
 
 /**

+ 1 - 1
packages/runtime-core/src/components/KeepAlive.ts

@@ -362,7 +362,7 @@ export const KeepAlive = (__COMPAT__
   ? /*@__PURE__*/ decorate(KeepAliveImpl)
   : KeepAliveImpl) as any as {
   __isKeepAlive: true
-  new (props?: VNodeProps & KeepAliveProps): {
+  new (): {
     $props: VNodeProps & KeepAliveProps
     $slots: {
       default(): VNode[]

+ 1 - 1
packages/runtime-core/src/components/Suspense.ts

@@ -129,7 +129,7 @@ export const Suspense = (__FEATURE_SUSPENSE__
   ? SuspenseImpl
   : null) as unknown as {
   __isSuspense: true
-  new (props?: VNodeProps & SuspenseProps): {
+  new (): {
     $props: VNodeProps & SuspenseProps
     $slots: {
       default(): VNode[]

+ 1 - 1
packages/runtime-core/src/components/Teleport.ts

@@ -514,7 +514,7 @@ function hydrateTeleport(
 // Force-casted public typing for h and TSX props inference
 export const Teleport = TeleportImpl as unknown as {
   __isTeleport: true
-  new (props?: VNodeProps & TeleportProps): {
+  new (): {
     $props: VNodeProps & TeleportProps
     $slots: {
       default(): VNode[]

+ 1 - 1
packages/runtime-core/src/h.ts

@@ -73,7 +73,7 @@ interface Constructor<P = any> {
   __isFragment?: never
   __isTeleport?: never
   __isSuspense?: never
-  new (props?: P): { $props: P }
+  new (...args: any[]): { $props: P }
 }
 
 type HTMLElementEventHandler = {

+ 1 - 1
packages/runtime-dom/src/components/TransitionGroup.ts

@@ -166,7 +166,7 @@ const TransitionGroupImpl: ComponentOptions = /*@__PURE__*/ decorate({
 })
 
 export const TransitionGroup = TransitionGroupImpl as unknown as {
-  new (props?: TransitionGroupProps): {
+  new (): {
     $props: TransitionGroupProps
   }
 }

+ 1 - 1
packages/runtime-vapor/src/apiDefineComponent.ts

@@ -32,7 +32,7 @@ type VaporComponentInstanceConstructor<T extends VaporComponentInstance> = {
   __isFragment?: never
   __isTeleport?: never
   __isSuspense?: never
-  new (props?: T['props']): T
+  new (...args: any[]): T
 }
 
 export type DefineVaporComponent<