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 { expectType, describe } from './utils'
|
||||
import {
|
||||
defineCustomElement,
|
||||
defineComponent,
|
||||
type VueElementConstructor
|
||||
} from 'vue'
|
||||
import { expectType, describe, test } from './utils'
|
||||
|
||||
describe('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,
|
||||
ComponentOptionsWithoutProps,
|
||||
ComponentPropsOptions,
|
||||
ComponentPublicInstance,
|
||||
ComputedOptions,
|
||||
EmitsOptions,
|
||||
MethodOptions,
|
||||
|
@ -21,7 +20,8 @@ import {
|
|||
ConcreteComponent,
|
||||
ComponentOptions,
|
||||
ComponentInjectOptions,
|
||||
SlotsType
|
||||
SlotsType,
|
||||
DefineComponent
|
||||
} from '@vue/runtime-core'
|
||||
import { camelize, extend, hyphenate, isArray, toNumber } from '@vue/shared'
|
||||
import { hydrate, render } from '.'
|
||||
|
@ -136,9 +136,9 @@ export function defineCustomElement<
|
|||
|
||||
// overload 5: defining a custom element from the returned value of
|
||||
// `defineComponent`
|
||||
export function defineCustomElement(options: {
|
||||
new (...args: any[]): ComponentPublicInstance
|
||||
}): VueElementConstructor
|
||||
export function defineCustomElement<P>(
|
||||
options: DefineComponent<P, any, any, any>
|
||||
): VueElementConstructor<ExtractPropTypes<P>>
|
||||
|
||||
/*! #__NO_SIDE_EFFECTS__ */
|
||||
export function defineCustomElement(
|
||||
|
|
Loading…
Reference in New Issue