diff --git a/packages/dts-test/defineCustomElement.test-d.ts b/packages/dts-test/defineCustomElement.test-d.ts index b81c0befe9f..f81f8b8fa61 100644 --- a/packages/dts-test/defineCustomElement.test-d.ts +++ b/packages/dts-test/defineCustomElement.test-d.ts @@ -99,4 +99,37 @@ describe('defineCustomElement using defineComponent return type', () => { expectType(instance.a) instance.a = 42 }) + + test('with required props', () => { + const Comp1Vue = defineComponent({ + props: { + a: { type: Number, required: true }, + }, + }) + const Comp = defineCustomElement(Comp1Vue) + expectType(Comp) + + const instance = new Comp() + expectType(instance.a) + instance.a = 42 + }) + + test('with default props', () => { + const Comp1Vue = defineComponent({ + props: { + a: { + type: Number, + default: 1, + validator: () => true, + }, + }, + emits: ['click'], + }) + const Comp = defineCustomElement(Comp1Vue) + expectType(Comp) + + const instance = new Comp() + expectType(instance.a) + instance.a = 42 + }) }) diff --git a/packages/runtime-dom/src/apiCustomElement.ts b/packages/runtime-dom/src/apiCustomElement.ts index efee4d8a9c1..2b472e73027 100644 --- a/packages/runtime-dom/src/apiCustomElement.ts +++ b/packages/runtime-dom/src/apiCustomElement.ts @@ -9,6 +9,7 @@ import { type ComponentOptionsBase, type ComponentOptionsMixin, type ComponentProvideOptions, + type ComponentPublicInstance, type ComputedOptions, type ConcreteComponent, type CreateAppFunction, @@ -153,14 +154,13 @@ export function defineCustomElement< // overload 3: defining a custom element from the returned value of // `defineComponent` export function defineCustomElement< - T extends DefineComponent, + // this should be `ComponentPublicInstanceConstructor` but that type is not exported + T extends { new (...args: any[]): ComponentPublicInstance }, >( options: T, extraOptions?: CustomElementOptions, ): VueElementConstructor< - T extends DefineComponent - ? ExtractPropTypes

- : unknown + T extends DefineComponent ? P : unknown > /*! #__NO_SIDE_EFFECTS__ */