expectType<number | undefined>(instance.a)
instance.a = 42
})
+
+ test('with required props', () => {
+ const Comp1Vue = defineComponent({
+ props: {
+ a: { type: Number, required: true },
+ },
+ })
+ const Comp = defineCustomElement(Comp1Vue)
+ expectType<VueElementConstructor>(Comp)
+
+ const instance = new Comp()
+ expectType<number>(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<VueElementConstructor>(Comp)
+
+ const instance = new Comp()
+ expectType<number>(instance.a)
+ instance.a = 42
+ })
})
type ComponentOptionsBase,
type ComponentOptionsMixin,
type ComponentProvideOptions,
+ type ComponentPublicInstance,
type ComputedOptions,
type ConcreteComponent,
type CreateAppFunction,
// overload 3: defining a custom element from the returned value of
// `defineComponent`
export function defineCustomElement<
- T extends DefineComponent<any, any, any, any>,
+ // this should be `ComponentPublicInstanceConstructor` but that type is not exported
+ T extends { new (...args: any[]): ComponentPublicInstance<any> },
>(
options: T,
extraOptions?: CustomElementOptions,
): VueElementConstructor<
- T extends DefineComponent<infer P, any, any, any>
- ? ExtractPropTypes<P>
- : unknown
+ T extends DefineComponent<infer P, any, any, any> ? P : unknown
>
/*! #__NO_SIDE_EFFECTS__ */