mirror of https://github.com/vuejs/core.git
fix(types): defineCustomElement using defineComponent return type with emits (#7937)
close #7782
This commit is contained in:
parent
341b5416b2
commit
5d932a8e6d
|
@ -1,5 +1,9 @@
|
||||||
import { defineCustomElement } from 'vue'
|
import {
|
||||||
import { expectType, describe } from './utils'
|
defineCustomElement,
|
||||||
|
defineComponent,
|
||||||
|
type VueElementConstructor
|
||||||
|
} from 'vue'
|
||||||
|
import { expectType, describe, test } from './utils'
|
||||||
|
|
||||||
describe('inject', () => {
|
describe('inject', () => {
|
||||||
// with object inject
|
// with object inject
|
||||||
|
@ -62,3 +66,20 @@ describe('inject', () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('defineCustomElement using defineComponent return type', () => {
|
||||||
|
test('with emits', () => {
|
||||||
|
const Comp1Vue = defineComponent({
|
||||||
|
props: {
|
||||||
|
a: String
|
||||||
|
},
|
||||||
|
emits: {
|
||||||
|
click: () => true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const Comp = defineCustomElement(Comp1Vue)
|
||||||
|
expectType<VueElementConstructor>(Comp)
|
||||||
|
|
||||||
|
expectType<string | undefined>(new Comp().a)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
|
@ -4,7 +4,6 @@ import {
|
||||||
ComponentOptionsWithObjectProps,
|
ComponentOptionsWithObjectProps,
|
||||||
ComponentOptionsWithoutProps,
|
ComponentOptionsWithoutProps,
|
||||||
ComponentPropsOptions,
|
ComponentPropsOptions,
|
||||||
ComponentPublicInstance,
|
|
||||||
ComputedOptions,
|
ComputedOptions,
|
||||||
EmitsOptions,
|
EmitsOptions,
|
||||||
MethodOptions,
|
MethodOptions,
|
||||||
|
@ -21,7 +20,8 @@ import {
|
||||||
ConcreteComponent,
|
ConcreteComponent,
|
||||||
ComponentOptions,
|
ComponentOptions,
|
||||||
ComponentInjectOptions,
|
ComponentInjectOptions,
|
||||||
SlotsType
|
SlotsType,
|
||||||
|
DefineComponent
|
||||||
} from '@vue/runtime-core'
|
} from '@vue/runtime-core'
|
||||||
import { camelize, extend, hyphenate, isArray, toNumber } from '@vue/shared'
|
import { camelize, extend, hyphenate, isArray, toNumber } from '@vue/shared'
|
||||||
import { hydrate, render } from '.'
|
import { hydrate, render } from '.'
|
||||||
|
@ -136,9 +136,9 @@ export function defineCustomElement<
|
||||||
|
|
||||||
// overload 5: defining a custom element from the returned value of
|
// overload 5: defining a custom element from the returned value of
|
||||||
// `defineComponent`
|
// `defineComponent`
|
||||||
export function defineCustomElement(options: {
|
export function defineCustomElement<P>(
|
||||||
new (...args: any[]): ComponentPublicInstance
|
options: DefineComponent<P, any, any, any>
|
||||||
}): VueElementConstructor
|
): VueElementConstructor<ExtractPropTypes<P>>
|
||||||
|
|
||||||
/*! #__NO_SIDE_EFFECTS__ */
|
/*! #__NO_SIDE_EFFECTS__ */
|
||||||
export function defineCustomElement(
|
export function defineCustomElement(
|
||||||
|
|
Loading…
Reference in New Issue