mirror of https://github.com/vuejs/core.git
fix(types/custom-element): `defineCustomElement` with required props (#11578)
This commit is contained in:
parent
8bcaad4a32
commit
5e0f6d5f8f
|
@ -99,4 +99,37 @@ describe('defineCustomElement using defineComponent return type', () => {
|
||||||
expectType<number | undefined>(instance.a)
|
expectType<number | undefined>(instance.a)
|
||||||
instance.a = 42
|
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
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -9,6 +9,7 @@ import {
|
||||||
type ComponentOptionsBase,
|
type ComponentOptionsBase,
|
||||||
type ComponentOptionsMixin,
|
type ComponentOptionsMixin,
|
||||||
type ComponentProvideOptions,
|
type ComponentProvideOptions,
|
||||||
|
type ComponentPublicInstance,
|
||||||
type ComputedOptions,
|
type ComputedOptions,
|
||||||
type ConcreteComponent,
|
type ConcreteComponent,
|
||||||
type CreateAppFunction,
|
type CreateAppFunction,
|
||||||
|
@ -153,14 +154,13 @@ export function defineCustomElement<
|
||||||
// overload 3: defining a custom element from the returned value of
|
// overload 3: defining a custom element from the returned value of
|
||||||
// `defineComponent`
|
// `defineComponent`
|
||||||
export function defineCustomElement<
|
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,
|
options: T,
|
||||||
extraOptions?: CustomElementOptions,
|
extraOptions?: CustomElementOptions,
|
||||||
): VueElementConstructor<
|
): VueElementConstructor<
|
||||||
T extends DefineComponent<infer P, any, any, any>
|
T extends DefineComponent<infer P, any, any, any> ? P : unknown
|
||||||
? ExtractPropTypes<P>
|
|
||||||
: unknown
|
|
||||||
>
|
>
|
||||||
|
|
||||||
/*! #__NO_SIDE_EFFECTS__ */
|
/*! #__NO_SIDE_EFFECTS__ */
|
||||||
|
|
Loading…
Reference in New Issue