From 67b6e0f894400f527fc5b20772ed124738df9446 Mon Sep 17 00:00:00 2001 From: Katashin Date: Tue, 25 Aug 2020 09:53:30 +0800 Subject: [PATCH] fix(types): relax ComponentPublicInstanceConstructor type for class components (#1943) --- packages/runtime-core/src/componentPublicInstance.ts | 2 +- packages/runtime-core/src/h.ts | 2 +- test-dts/defineComponent.test-d.tsx | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/runtime-core/src/componentPublicInstance.ts b/packages/runtime-core/src/componentPublicInstance.ts index 2205e1ae484..28814527150 100644 --- a/packages/runtime-core/src/componentPublicInstance.ts +++ b/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< diff --git a/packages/runtime-core/src/h.ts b/packages/runtime-core/src/h.ts index d1fe4f0aceb..1939475b4ef 100644 --- a/packages/runtime-core/src/h.ts +++ b/packages/runtime-core/src/h.ts @@ -65,7 +65,7 @@ interface Constructor

{ __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 diff --git a/test-dts/defineComponent.test-d.tsx b/test-dts/defineComponent.test-d.tsx index cd08a428893..18c3338abeb 100644 --- a/test-dts/defineComponent.test-d.tsx +++ b/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', () => {