Sfoglia il codice sorgente

fix(types): relax ComponentPublicInstanceConstructor type for class components (#1943)

Katashin 5 anni fa
parent
commit
67b6e0f894

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

@@ -107,7 +107,7 @@ export type ComponentPublicInstanceConstructor<
   __isFragment?: never
   __isTeleport?: never
   __isSuspense?: never
-  new (): T
+  new (...args: any[]): T
 }
 
 export type CreateComponentPublicInstance<

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

@@ -65,7 +65,7 @@ interface Constructor<P = any> {
   __isFragment?: never
   __isTeleport?: never
   __isSuspense?: never
-  new (): { $props: P }
+  new (...args: any[]): { $props: P }
 }
 
 // The following is a series of overloads for providing props validation of

+ 10 - 0
test-dts/defineComponent.test-d.tsx

@@ -701,6 +701,16 @@ describe('defineComponent', () => {
       components: { comp }
     })
   })
+
+  test('should accept class components with receiving constructor arguments', () => {
+    class Comp {
+      static __vccOpts = {}
+      constructor(_props: { foo: string }) {}
+    }
+    defineComponent({
+      components: { Comp }
+    })
+  })
 })
 
 describe('emits', () => {