fix(types): defineCustomElement using defineComponent return type with emits (#7937)

close #7782
This commit is contained in:
Rudy 2023-11-10 13:52:54 +08:00 committed by GitHub
parent 341b5416b2
commit 5d932a8e6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 7 deletions

View File

@ -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)
})
})

View File

@ -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(